当他们被触摸时,我想在我的精灵中做一个动作,这是动作方法:
-(void) spriteEffect
{
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];
}
现在,我的问题是,我不知道如何使触摸动作与精灵连接;我应该用这个吗?
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
Msp位于.png图像中,并指定了.plist.
最佳答案
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 1)
{
// Add Your Action
}
}
要么
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SpriteThouch)];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:gr];
并调用方法SpriteThouch
-(void)SpriteThouch
{
// code here
}