我試圖基本上在檢測到觸摸時放大按鈕。這是我的場景:行動將不會運行在cocos2d中的ccTouchBegan中的CCSprite對於iphone
@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 BTW
Rob:謝謝你的建議。我有一種預感,那是因爲我在「init」中添加了精靈,而不是「onEnter」,但我最終將其縮小到了確切的原因。這是因爲我沒有[super onEnter];哎呀。我補充說,它動畫很好。很高興知道! – taber 2010-03-03 08:38:31
沒問題。幾個星期前,我犯了同樣的錯誤。忘記調用[super onEnter]與Cocos2D嚴重混淆。別忘了打電話給[super onExit]! – 2010-03-03 16:09:01
不錯,我遇到了同樣的問題,謝謝你指出缺少[super onEnter]是問題的原因。我添加了這個答案,以使解決方案更加清晰。 – 2011-09-02 14:53:45