cocos2d iphone - How to stop a character from going out of the screen? -


i'm making game ninja supposed go , down. wrote method button problem when ninja @ top of screen (landscape) still goes when touch button so, did

-(void)uppressed:(id)sender { if(cgpointequaltopoint(ninja.position, ccp(0,280))) {     id standstill = [ccmoveby actionwithduration:0 position:ccp(0,0)];     [ninja runaction:standstill]; }else { id moveup = [ccmoveby actionwithduration:.1 position:ccp(0,80)]; [ninja runaction:moveup]; } } 

and problem still exists. help?

i.e when ninja @ (0,280), want button nothing

you testing equality. if condition true if ninja @ {0, 200}.

try instead:

if (ninja.position.y < 280) {     // no need run action     ninja.position = cgpointzero;       // should stop potentially running (move) action     [ninja stopallactions]; } else ... 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -