The order for my game loop?

Hi, i’m developing a platform game. I have a stage with a tiled-base map, my player, enemies, items…

I want to know the correct order for my game loop.----
Read input
update player (with input)
update enemies

update collision player-map(means update player again with collision)
update collision player-enemies
update collision player-items

update map(some tiles can be moved)
update windows(scroll)

draw map
draw items
draw enemies
draw hero

That order is ok?
What should i change?

Thanks.

Hi, i’m developing a platform game. I have a stage with a tiled-base map, my player, enemies, items…

I want to know the correct order for my game loop.


Read input
update player (with input)
update enemies

update collision player-map(means update player again with collision)
update collision player-enemies
update collision player-items

update map(some tiles can be moved)
update windows(scroll)

draw map
draw items
draw enemies
draw hero

That order is ok?
What should i change?

Thanks.

That looks good to me. The only thing I’m wondering (and I’m not sure if this is the right thing to do) if you should mix the update functions with the collision detection.
With a top down shooter you may have an enemy fire and then the next function says they collided and blew up. That is perfectly fine if it is what you want.

Personally in the update function I:
apply movement to the object
check collision
apply the rest of the commands

But that all comes down to personal preference.

Good luck!

  • Micah

Thanks MBrening. I’ll try both methods :smiley:

If someone know another order i could use, please post it.

Mix it up and have some fun with it. I like to make comments that explain what I’m doing in steps before I even start to write code. For this I might write something like this:
//check for events
//decide what the events do
//apply the data updates to objects
//use the info in ojects to decide what to do with them
//do it
//check to see if collisions happened
//start the reasults of the collisions
//draw stuff in layers
//update screen
After this I would put in details like, when, or do I do I take a snapshot of the background before I draw on it? Depends on if it’s static or not I guess. Until I add the details like this I just make it work and then refine it later. I like to look at example code and see why do the things they do as well to learn basic design. Most people design very poorly so keep an open mind and shake things up now and again :slight_smile:

That’s a good advice :slight_smile: , thank you.