How to activate CCMenuItem and move CCSprite with one click

Blockquote

I have a button CCMenuItem

that I would like to click and then clicking down will create a new CCSprite

one that can be dragged while continuing to use the same press. Basically you press the down button and drag a new sprite that you can move around the screen.

I have already subclassed CCMenuItemImage

to create a new sprite on click, but the new sprite will not detect any touch without picking it up and starting a new touch. Can I get this sprite to view or use my existing touch with a button press so I can drag it away without lifting my finger?

Any thoughts would be greatly appreciated.

My subclass CCMenuItemImage

that works great for reference:

@interface CCMenuItemImageAdvanced : CCMenuItemImage {    
}

-(void) selected;
-(void) unselected;

@end

@implementation CCMenuItemImageAdvanced

-(void) selected {
[super selected];

// Method that creates the ccsprite
[_sharedGameHud createSprite:self];
}

-(void) unselected {
[super unselected];
}

@end

      

+3


source to share


2 answers


take a look at

[CCMenu ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event]

      

You can subclass CCMenu and instead of calling

[selectedItem_ selected];

      



in the above method, you can create a new method in CCMenuItemImageAdvanced

- (void)selectedWithTouch:(UITouch*)touch;

      

then use that touch to move the sprite.

+1


source


Perhaps you could create CCSprite hidden on load and on touch move check if CCSprite is visible and if it makes it follow with your finger. CCButton will simply have to render CCSprite, making it traversable.



+1


source







All Articles