Reputation: 315
How would i trigger - (void)onRightButtonClicked:(id)sender
when the button is being pressed, not when it has been pressed (let go).
This is the code for the button
rightButton = [CCButton buttonWithTitle:@"" spriteFrame:[CCSpriteFrame frameWithImageNamed:@"right.png"]];
rightButton.position = ccp(self.contentSize.width/3.65, self.contentSize.height/10);
[rightButton setTarget:self selector:@selector(onRightButtonClicked:)];
[self addChild:rightButton];
And then what happens after the button has been pressed.
- (void)onRightButtonClicked:(id)sender
{
CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:walkAnim];
CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction];
[dino runAction:repeatingAnimation];
}
Upvotes: 2
Views: 2296
Reputation: 3012
I'm afraid there is no 1-2 liner for that one, if you check CCButton.m
you can see when actions are triggered
- (void) touchUpInside:(UITouch *)touch withEvent:(UIEvent *)event
{
[super setHitAreaExpansion:_originalHitAreaExpansion];
if (self.enabled)
{
[self triggerAction];
}
self.highlighted = NO;
}
If you want ALL buttons in your game to have this behaviour just move [self triggerAction]
to - (void) touchEntered:(UITouch *)touch withEvent:(UIEvent *)event
in CCButton
.
Make a custom subclass of CCButton
where you override the touchUpInside
and touchEntered
methods. But since these are not public you would have to create a CCButton_Protected.h
header where you import your normal CCButton
header and put the private method signatures that you want to override in there.
Upvotes: 5