Note that there are some explanatory texts on larger screens.

plurals
  1. POAction on press CCMenuItem. not on unpress
    text
    copied!<p>I'm developing an app on cocos2d. I heard it is recommend to make my controls using CCMenu class. So, I made a button, set target and selector. But selector colled only when I unpress my button. how can I make it be called at rhe moment I pressed the button?</p> <pre><code>#import "Button.h" @implementation Button + (id)buttonWithImage:(NSString*)file atPosition:(CGPoint)position target:(id)target selector:(SEL)selector { CCMenu *menu = [CCMenu menuWithItems:[ButtonItem buttonWithImage:file target:target selector:selector], nil]; menu.position = position; return menu; } @end @implementation ButtonItem + (id)buttonWithImage:(NSString*)file target:(id)target selector:(SEL)selector { return [[[self alloc] initWithImage:file target:target selector:selector] autorelease]; } - (id)initWithImage:(NSString*)file target:(id)target selector:(SEL)selector { if(self = [super initWithTarget:target selector:selector]) { back = [[CCSprite spriteWithFile:@"DPad_BG.png"] retain]; back.anchorPoint = ccp(0,0); backPressed = [[CCSprite spriteWithFile:@"DPad_BG.png"] retain]; backPressed.anchorPoint = ccp(0,0); [self addChild:back]; self.contentSize = back.contentSize; CCSprite* image = [CCSprite spriteWithFile:file]; [self addChild:image z:1]; image.position = ccp(self.contentSize.width / 2, self.contentSize.height / 2); } return self; } -(void) selected { [self removeChild:back cleanup:NO]; [self addChild:backPressed]; [super selected]; } -(void) unselected { [self removeChild:backPressed cleanup:NO]; [self addChild:back]; [super unselected]; } // this prevents double taps - (void)activate { [super activate]; [self setIsEnabled:NO]; [self schedule:@selector(resetButton:) interval:0.5]; } - (void)resetButton:(ccTime)dt { [self unschedule:@selector(resetButton:)]; [self setIsEnabled:YES]; } - (void)dealloc { [back release]; [backPressed release]; [super dealloc]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload