Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] Trouble with classes

This topic is 6382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m rather new to java and I''m having a problem with classes... Right now I''m trying to make a pacman game, the main class that gets called when the applet loads works fine, so then I tried to make a class for the ghosts. It works fine when I initialize just one instance, e.g. Ghost ghosts = new Ghost(); but when I try to initialize an array of four ghosts, the applet only shows a gray screen.. although it doesn''t display any errors I initialize the array of ghosts like this.. Ghost ghosts[] = new Ghost[4]; If you can think of any reason that could cause this please post. Thank you very much, Laotzu

Share this post

Link to post
Share on other sites
Remember that you need to initialize the objects in your array.

When you create the array with the line...

Ghost ghosts[] = new Ghost[4];

... you only create a place holder for 4 ghosts.

You should then have a loop or some other method of initializing the ghosts.

For example.

for (int loop = 0; loop < 4; loop++) {
ghosts[loop] = new Ghost();

This will create the Ghosts in your array.

I hope this helps.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!