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
source to share
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.
source to share