xcode - Deducting lives on Cocos2D -
say if had apple falling top of screen , player needs catch before gone of screen @ bottom. want give player 3 (lives) chances catch apple. each time object reaches bottom of screen lives should go -1.
apple = [ccsprite spritewithfile:@"apple2.png"]; apple.position = ccp(250,768); [self addchild:apple]; this apple sprite created above gets updated until reaches bottom of screen:
-(void) calleveryframe:(cctime)dt { apple.position = ccp(apple.position.x, apple.position.y -200*dt); if (apple.position.y < -100+64) { apple.position = ccp(apple.position.x, 768); } } the if statement testing make apple fall again if missed.
any appreciated!, thanks.
create integer inside @interface u did ccspirte apple this
@interface nameofmyclass : ccscene { int mylife; } set mylife 3, mylife = 3; in init method, inside -(void) calleveryframe:(cctime)dt
if (apple.position.y < -100+64) { apple.position = ccp(apple.position.x, 768); mylife--; } if (mylife == 0) { //game_over }
Comments
Post a Comment