ios - How to create a game loop in Sparrow and refresh the display each frame cycle? -


i've been scouring web past 2 days trying find complete example of how use built-in game loop features in sparrow ios development. working on tower defense type of game school project. player controls gun turret in center of screen while tanks enter screen randomly 4 sides. here link screen shot:

https://www.dropbox.com/s/sqleuqza9dcgiqs/ios%20simulator%20screen%20shot%20apr%2019%2c%202013%2010.53.54%20pm.png

i have "tankmanager" class creates , handles instances of "tank" class storing instances of tank in nsmutablearray called "activetanks", , put "tankimage" "tanksprite" nested in "tankmanagersprite" nested in main "_contents" sprite. can see in image @ link above, show fine.

i want animate tanks. reading understand need have game loop calls method every fraction of second. according sparrow wiki (http://wiki.sparrow-framework.org/manual/animation), use sparrow's built-in game loop feature similar following:

add code init function in class want use it(the class needs spevent:)

// e.g. in init-method [self addeventlistener:@selector(onenterframe:) atobject:self fortype:sp_event_type_enter_frame]; 

and put code somewhere (i chose put in tankmanager.m file, don't know if right):

- (void)onenterframe:(spenterframeevent *)event {     (tank *thistank in activetanks)     {         [thistank move:event.passedtime];     } } 

and in "-(void)move:(double)timeelapsed;" function in "tank" class:

-(void)move:(double)timeelapsed{     nslog(@"xcoord: %f", tankvector.vertex.xcoord);     nslog(@"ycoord: %f", tankvector.vertex.xcoord);     tankvector.vertex.xcoord += (timeelapsed *20);     tankvector.vertex.ycoord += (timeelapsed *20); } 

as result nslog() output looks (only 1 tank being generated):

2013-04-20 00:35:43.449 tank turret game[7815:c07] xcoord: 172.677765 2013-04-20 00:35:43.450 tank turret game[7815:c07] ycoord: 172.677765 2013-04-20 00:35:43.482 tank turret game[7815:c07] xcoord: 173.343170 2013-04-20 00:35:43.483 tank turret game[7815:c07] ycoord: 173.343170 2013-04-20 00:35:43.516 tank turret game[7815:c07] xcoord: 174.010696 2013-04-20 00:35:43.516 tank turret game[7815:c07] ycoord: 174.010696 2013-04-20 00:35:43.549 tank turret game[7815:c07] xcoord: 174.679245 2013-04-20 00:35:43.550 tank turret game[7815:c07] ycoord: 174.679245 2013-04-20 00:35:43.583 tank turret game[7815:c07] xcoord: 175.349762 2013-04-20 00:35:43.584 tank turret game[7815:c07] ycoord: 175.349762 2013-04-20 00:35:43.616 tank turret game[7815:c07] xcoord: 176.020950 2013-04-20 00:35:43.616 tank turret game[7815:c07] ycoord: 176.020950 2013-04-20 00:35:43.649 tank turret game[7815:c07] xcoord: 176.679245 2013-04-20 00:35:43.650 tank turret game[7815:c07] ycoord: 176.679245 

so far good. when @ screen, nothing moving. i'm @ wits end. know solution super easy, life of me can't find it. appreciated.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -