Domanda

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
È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top