I'm using Cocos2D 3.0 for iOS devices.
In my HUD class I have 4 buttons (SneakyInput Library), Left Right ButtonA and ButtonB, all works good, but when I move my finger (without lifting of the screen) the button is hold.
Now what happens is that when I press a button, and move my finger button stay pressed until you lift your finger.
I want:
When I touch the buttonA, and move my finger to the buttonB, buttonB button works.
I have seen many games that have implemented this without problems, but for now I can't. >_<.
My game works perfectly, I just want to implement this option to make it more manageable.
Here is the code of the implementation of the Sneaky buttons:
-(void) loadControls {
//Screen Size
CGSize winSize = [[CCDirector sharedDirector] viewSize];
//Load Spritesheets
CCSprite *botonA = [CCSprite spriteWithImageNamed:@"botona.png"];
CCSprite *left = [CCSprite spriteWithImageNamed:@"izquierda.png"];
//Boton A
SneakyButtonSkinnedBase *baseBotonA = [[SneakyButtonSkinnedBase alloc] init];
baseBotonA.position = ccp(winSize.width - botonA.contentSize.width ,botonA.contentSize.height);
baseBotonA.defaultSprite = [CCSprite spriteWithImageNamed:@"botona.png"];
baseBotonA.activatedSprite = [CCSprite spriteWithImageNamed:@"botona.png"];
baseBotonA.pressSprite = [CCSprite spriteWithImageNamed:@"botonaselected.png"];
baseBotonA.button = [[SneakyButton alloc] initWithRect:CGRectMake(0, 0, 100, 100)]; //Ajustar
buttonA = baseBotonA.button;
buttonA.isToggleable = YES;
//Boton B
SneakyButtonSkinnedBase *baseBotonB = [[SneakyButtonSkinnedBase alloc] init];
baseBotonB.position = ccp(winSize.width - (botonA.contentSize.width * 2) - (botonA.contentSize.width / 2) ,botonA.contentSize.height);
baseBotonB.defaultSprite = [CCSprite spriteWithImageNamed:@"botonb.png"];
baseBotonB.activatedSprite = [CCSprite spriteWithImageNamed:@"botonb.png"];
baseBotonB.pressSprite = [CCSprite spriteWithImageNamed:@"botonbselected.png"];
baseBotonB.button = [[SneakyButton alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
buttonB = baseBotonB.button;
buttonB.isToggleable = YES;
//Boton Left
SneakyButtonSkinnedBase *baseBotonLeft = [[SneakyButtonSkinnedBase alloc] init];
baseBotonLeft.position = ccp(left.contentSize.width,left.contentSize.height);
baseBotonLeft.defaultSprite = [CCSprite spriteWithImageNamed:@"izquierda.png"];
baseBotonLeft.activatedSprite = [CCSprite spriteWithImageNamed:@"izquierda.png"];
baseBotonLeft.pressSprite = [CCSprite spriteWithImageNamed:@"izquierdaselected.png"];
baseBotonLeft.button = [[SneakyButton alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
buttonLeft = baseBotonLeft.button;
buttonLeft.isToggleable = YES;
//Boton Right
SneakyButtonSkinnedBase *baseBotonRight = [[SneakyButtonSkinnedBase alloc] init];
baseBotonRight.position = ccp((left.contentSize.width * 2) + (left.contentSize.width / 2),left.contentSize.height);
baseBotonRight.defaultSprite = [CCSprite spriteWithImageNamed:@"derecha.png"];
baseBotonRight.activatedSprite = [CCSprite spriteWithImageNamed:@"derecha.png"];
baseBotonRight.pressSprite = [CCSprite spriteWithImageNamed:@"derechaselected.png"];
baseBotonRight.button = [[SneakyButton alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
buttonRight = baseBotonRight.button;
buttonRight.isToggleable = YES;
[layoutBox addChild:baseBotonA];
[layoutBox addChild:baseBotonB];
[layoutBox addChild:baseBotonLeft];
[layoutBox addChild:baseBotonRight];
[self addChild:layoutBox];
}
Sorry for my bad english, i try it without translator :(
Set the claimsUserInteraction
property to NO
on your buttons.
From the Cocos2D documentation for CCResponder
:
/**
* Locks the touch to the node if touch moved outside
* If a node claims user interaction, the touch will continue to be sent to the node, no matter where the touch is moved
* If the node does not claim user interaction, a touch will be cancelled, if moved outside the nodes detection area
* If the node does not claim user interaction, and a touch is moved from outside the nodes detection area, to inside, a touchBegan will be generated.
*/
@property (nonatomic, assign) BOOL claimsUserInteraction;