4
\$\begingroup\$

I am an experienced app developer (c#) however I am just looking at starting 2d game development.

I have read some articles and understand the concept of the gaming loop controlling the application flow. However there seems few articles explaining general concepts for an existing developer. From these I assuming that each on screen item becomes it's own object and handles it's own location, drawing, collision detection etc. (though correct me if I am wrong)

My question is how to control the list of items on the screen? Are these stored in a simple collection and then removed as they fall out of play and is this collection held by the game engine or individual components? An example would be bullets from a gun?

\$\endgroup\$
3
  • \$\begingroup\$ Have you looked into XNA? As a C# programmer, it is really, really, amazing. \$\endgroup\$
    – Nate
    Dec 13, 2010 at 21:23
  • \$\begingroup\$ I'm assuming he is looking at Windows Phone 7, so probably he is looking into XNA or Silverlight. \$\endgroup\$ Dec 13, 2010 at 23:23
  • \$\begingroup\$ Actually at the moment I am just looking generally at concepts and can write many languages. I have looked at both XNA and Silverlight and have to agree they are very good. \$\endgroup\$
    – John
    Dec 14, 2010 at 7:56

3 Answers 3

5
\$\begingroup\$

Are these stored in a simple collection and then removed as they fall out of play and is this collection held by the game engine or individual components?

There are a lot of ways of handling it, but sure, that's one way.

What some games do is have a giant list of all Entities in the world (which implies that there's some World class, or equivalent, managing all this stuff), where everything in the game is an Entity.

Your update loop might look something like this:

update all entities
remove entities that are marked for removal
draw all entities

Some other games do sublists for different types of entities. Like there's a list of projectiles in the world whose loop is treated like the above. This way you don't necessarily have to have everything in the world have a singular base class.

\$\endgroup\$
1
\$\begingroup\$

I was having issues with this same thing, one good source to look at is the Octane 2D/3D Engine. I like the way it solves this exact problem; simply.

There are many ways to do it, but the general rule of thumb (for most things actually) is keep it as simple as you need it. You may need to up-grade it later, probably not.

A simple deque or list of entities is going to be the easiest. Then you simply need to iterate the list each game loop, updating all the entities (unless some ISDEAD flag has been set on them).

And your 'on screen item' is best described as a game object or game entity. :)

\$\endgroup\$
0
\$\begingroup\$

I've just started working on a 2-d game myself on android. I have a map and some menu/windows on the screen. I draw the map first, and for the menus, I have something like this in the main drawing loop:

drawMap(canvas);    
if(menuActive) drawMenu(canvas);

The drawMenu will take care of drawing the menu at the correct place. However, to check whether the user clicked on the menu, I have something like this where I read in inputs:

if(menuActive) handle_menuAction(event);

Here I check whether the user clicked the menu location. The handle_menuAction can do something like return true if the user hit the menu, or return false if they didn't.

If I wanted to turn off the menu, I just set menuActive = false and none of the drawMenu() or handle_menuAction() will be activated and I don't have to worry about it anymore.

Hope this helps.

\$\endgroup\$
2
  • \$\begingroup\$ Did you consider using a State-Machine for your game loop? I'm pretty sure your game would benefit from it. Just imagine that you'll have to add an intro, cut-scene etc. to your game. That's going to be a lot of ifs. I suggest you read this question and the answers: gamedev.stackexchange.com/questions/651/… \$\endgroup\$
    – bummzack
    Dec 13, 2010 at 15:36
  • \$\begingroup\$ I have been unsuccessful in implementing state machines into the game. My 'game loop' is actually a thread just drawing things on to the screen. When the user touches the menu, I think of it as an 'interrupt' handled in a different thread which has to synchronize with the view so that I don't get concurrency errors. These two threads are only instantiated when the user is doing a 'battle' and I should be able to use these two threads w/diff inputs in a different 'battle'. I think another class outside will handle the actual state machine to determine what point of the game I am currently in. \$\endgroup\$
    – f20k
    Dec 13, 2010 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .