我正在尝试实现此方法:
-(void) SpriteThouch
{
CCSprite *actionEffect = avatar;
id jump = [CCJumpBy actionWithDuration:1 position: ccp(0, 0) height:50 jumps:1];
id sequence = [CCSequence actions: jump, nil];
[actionEffect runAction:sequence];
}
进入一个带有字符的精灵,我正在使用一个包含所有字符的.png,并使用一个.plist来选择每个字符。我的问题是,当我触摸它们一次时,我找不到让角色跳跃的方法。跳跃方法有效,但是当我尝试将其实现到触摸动作中时,它什么也没做。我正在尝试这种方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 1)
{
CCSprite *actionEffect = avatar;
id jump = [CCJumpBy actionWithDuration:1 position: ccp(0, 0) height:50 jumps:1];
id sequence = [CCSequence actions: jump, nil];
[actionEffect runAction:sequence];
}
}
和
UITapGestureRecognizer *gr = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector (SpriteThouch:)] autorelease];
[gr setNumberOfTapsRequired: 1];
[[[CCDirector sharedDirector] view] addGestureRecognizer:gr];
你能帮助我吗?谢谢!