iphonecocoa-touchcocos2d-iphoneccmenuitem

How can I activate a CCMenuItem and move a CCSprite with a single touch


Blockquote

I have a CCMenuItem button that I'd like to be able to press down then while still pressed down, will create a new CCSprite that can be dragged away while still using the same press. Basically you press the button down and drag off a new sprite that you can move around the screen.

I have already subclassed CCMenuItemImage to create the new sprite while pressed down but the new sprite won't detect any touch without lifting up and beginning a new touch. Can I get this sprite to see or use my existing touch from the press of the button to allow me to drag it away without lifting my finger?

Any thoughts would be greatly appreciated.

My subclass of CCMenuItemImage which is working fine for reference is:

@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

Solution

  • look into

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

    You could subclass CCMenu and instead of calling

    [selectedItem_ selected];
    

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

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

    then use that touch to move the sprite.