gpt4 book ai didi

ios - cocos2d 中 Sprite 的触摸 Action

转载 作者:可可西里 更新时间:2023-11-01 05:56:34 24 4
gpt4 key购买 nike

我想在我的 Sprite 被触摸时做一个 Action ,这是 Action 方法:

-(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];
}

现在,我的问题是,我不知道如何让触摸 Action 与 Sprite 连接;我应该用这个吗?

- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

Msp 在分配了 .plist 的 .png 图像中。

最佳答案

- (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

}

关于ios - cocos2d 中 Sprite 的触摸 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14479158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com