tags:

views:

129

answers:

1

I have designed a game that the main character will jump in the screen for gaining points, but i need the player can only touch after the character landed, i had done following thing but still no work, what have i missed??

(BOOL)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {

 UITouch *touch = [touches anyObject];

 CGPoint point = [touch locationInView: [touch view]];

 point =  [[Director sharedDirector] convertCoordinate: point];

 id jump = [JumpTo actionWithDuration:0.5 position:ccp(point.x,point.y) height:100 jumps:1];
 [plainSprite runAction:jump];

 if (![jump isDone])
 {
  isTouchEnabled=NO;
 }

return YES;

}

A: 

The problem is that JumpTo works "asynchronously" (well, not really, but it's going to give the appearance of an asynchronous call). Here's how it works:

Creating any IntervalAction (like JumpTo) just creates an object that keeps track of some property such as position, opacity, etc. The game loop then moves on, calling the action periodically to update its property.

So, in your case, the if (![jump isDone]) won't work, because it is called immediately after the action is created, not after it is done.

So, how to solve the problem -

First create a jumpIsDone method that re-enables your sprite. Then:

    isTouchEnabled = NO;
[plainSprite runAction: [JumpTo actionWithDuration: 0.5 position:ccp(point.x, point.y) height:100 jumps:1]];
       [plainSprite runAction: [Sequence actionOne: [DelayTime actionWithDuration: 0.5]
                                        two: [CallFunc actionWithTarget: self selector: @selector(jumpIsDone)]]];
Chris Garrett