Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 4:51 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Main Game Loop Questions
PostPosted: Sun Apr 01, 2012 4:34 pm 
Offline

Joined: Tue Mar 27, 2012 9:38 pm
Posts: 9
Hi guys,

My biggest problem thus far seems to be design related. In your main game loop, how much code is supposed to actually be going on? Is ALL the code for transition maps, loading enemies, simulating fights all supposed to be in one class? I don't know how to spread it out between multiple classes, and my update method is getting out of control.

Any advice?

Thanks in advance!


Top
 Profile  
 
PostPosted: Sun Apr 01, 2012 4:37 pm 
Offline
Regular

Joined: Sun Oct 30, 2011 4:47 pm
Posts: 184
Location: Mittweida, Saxony, Germany
For larger applications you should try to maintain lists of the update and the render loop that can be triggered one after another.

So in case a entity/system/object needs to be updated or rendered its added in such lists and the respective methods are called then.

Nitram

_________________
http://illarion.org


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 4:39 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
I typically separate them.

By default a game state will have init, update, render (plus input events).

I'll do something like this:

Code:

Map map;
List<Enemy> enemies = new ArrayList<Enemy>();

init() {
   map = new Map();
   map.init();
   for (int i=0; i<10; i++) {
      enemies.add(new Enemy());
      enemies.get(i).init();
   }
}

update() {
   map.update();
   for (Enemy enemy : enemies) {
      enemy.update();
   }
}

render() {
   map.render();
   for (Enemy enemy : enemies) {
      enemy.render();
   }
}



Map would then know how to render it's self or update it's self when called. Put map code in map, enemy code in enemy, etc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group