gpt4 book ai didi

iphone - Action 不会在 iPhone 版 cocos2d 中的 ccTouchBegan 中的 CCSprite 上运行

转载 作者:行者123 更新时间:2023-12-03 20:11:21 25 4
gpt4 key购买 nike

我试图在检测到触摸后立即放大按钮。这是我的场景:


@implementation HomeScene

-(id) init
{
if((self = [super init])) {
...
// sp_btn_story is retained...
sp_btn_story = [[CCSprite spriteWithFile:@"main_menu_btn.png"] retain];
sp_btn_story.position = ccp(size.width - 146, 110);
[self addChild: sp_btn_story];
...
}
return self;
}

-(void) onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

-(void) onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
NSLog(@"tapped!");
sp_btn_story.scaleX = 2;

[sp_btn_story stopAllActions];
[sp_btn_story runAction: [CCScaleTo actionWithDuration:0.5f scale:1.2f]];
return YES;
}

...

@end

正如预期的那样,它很好地缩放了 X。 (我把它放在那里进行测试。)但是由于某种原因该操作没有运行。 :( 有人有什么想法吗?

编辑:使用 cocos2d 0.99 顺便说一句。

最佳答案

此问题的答案(从提问者自己的评论中重新发布,以使其更加明显):

It's quite important to call

[super onEnter];

if you overwrite this method in a subclass or strange things may happen. Cocos2D will not be happy.

This applies to other (if not all) methods as well, e. g. always call

[super onExit];

as well.

关于iphone - Action 不会在 iPhone 版 cocos2d 中的 ccTouchBegan 中的 CCSprite 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2353774/

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