3

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


@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 顺便说一句。

4

2 回答 2

1

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

打电话很重要

[super onEnter];

如果您在子类中覆盖此方法,否则可能会发生奇怪的事情。Cocos2D 不会高兴的。

这也适用于其他(如果不是全部)方法,例如总是调用

[super onExit];

也是。

于 2011-09-02T14:59:37.787 回答
0

不完全确定会发生什么。看起来你所拥有的应该可以正常工作,但你可能想尝试应用不同的动作来sp_btn_story喜欢淡入或淡出,看看是否至少有任何动作会起作用。如果失败,您也可以尝试在代码的不同部分应用该操作。这些不是解决方案,但它们可以提供证据来表明究竟发生了什么。

于 2010-03-01T22:31:57.157 回答