The action will not be performed on CCSprite from ccTouchBegan in cocos2d for iphone

I try to basically scale the button as soon as a touch is detected. Here is 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 X perfectly, as expected. (I threw this to check.) But the action for some reason does not work. :( Does anyone have any ideas?

Edit: use cocos2d 0.99 battles.

+3
source share
2 answers

The answer to this question (edited from the author’s own comment to make it more visible):

It’s very important to call

[super onEnter];

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

( ) , e. .

[super onExit];

.

+1

, . , , sp_btn_story, , , , - . . , , .

0

Source: https://habr.com/ru/post/1734823/


All Articles