我正在尝试实施此方法:
-(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];
你可以帮帮我吗?谢谢!