Java2DGame rendering NPC's

Started by
10 comments, last by Nicholas Kong 10 years, 4 months ago

So I managed to spawn NPC's of the same type in multiple locations. But now I'm having trouble updating them correctly. I have a start class(includes game loop), a levelLoader class(where I create and spawn NPC's appropriate for the level), and a seperate class for each NPC(each has it's own spawn and update method. I need to update each NPC from the Start class, but since I created the object in the LevelLoader class I can't update the correct variables of each NPC. I can't spawn the NPC's in the Start class because the LevelLoader class decides which NPC's to spawn depending on the level. I'm not sure if I said this in a very understandable way, but any help would be appreciated.

Advertisement
You might want to rename your start class to be a game class. It is much more clear to people and it is very common class to use.

To answer your question, you can make npc to be an instance variable in that levelloader and then use accessor or getter method to refer to that npc.

You should post your code. It does help us a lot to see your code design. I also sense some design issues. Your npc should not be created in a levelloader class. Levelloader should do as it say load levels. You can create it in a class called level1 that would be more reasonable.

This topic is closed to new replies.

Advertisement