3

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
XBXSlagHeap
  • 174
  • 1
  • 16

2 Answers2

1

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.

Sebastian
  • 7,670
  • 5
  • 38
  • 50
1

Maybe you could create the CCSprite hidden on load and in touch moved check if the CCSprite is visible and if it is make it follow the finger. The CCButton will just have to unhide the CCSprite, making it available for moving.

condor304
  • 209
  • 3
  • 8
  • Thanks for the feedback condor304. I was gonna go this route or a similar one if I couldn't figure out a better way. I'm off with Sebastian's suggestion but giving you a bump too for your feedback. :) – XBXSlagHeap Jan 31 '13 at 22:57