views:

494

answers:

1

Hi, I'm trying to basically scale up a button as soon as a touch is detected. Here's my Scene:


@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

It scales the X just fine, as expected. (I threw that in there to test.) But the action is not running for some reason. :( Anyone have any ideas?

Edit: using cocos2d 0.99 btw.

A: 

Not complete sure what could be going on. Looks like what you have should work fine but you may want to try applying a different action to sp_btn_story like fade in or fade out to see if at least any action will work. Failing that you could also try applying the action in a different part of your code. These are not solutions but they may provide evidence to indicate what exactly is going on.

Rob Segal
Rob: thanks a bunch for the suggestions. I had a hunch that it was because I was adding the sprite in "init" and not "onEnter," but I finally narrowed it down to the exact cause. It was the because I didn't have [super onEnter]; Oops. I added that and it animated just fine. Good to know!
taber
No problem. I made that exact same mistake some weeks ago. Forgetting to call [super onEnter] seriously messes with Cocos2D. Don't forget to call [super onExit] as well!!
Rob Segal