我正在为iOS设备使用Cocos2D 3.0。
在我的HUD课程中,我有4个按钮(SneakyInput Library),Left Right ButtonA和ButtonB,一切正常,但是当我移动手指(没有抬起屏幕)时,按钮就会保持。
现在发生的事情是,当我按下一个按钮,然后按住我的手指按钮,直到你抬起手指为止。
我想:
当我触摸按钮A,然后将手指移动到按钮B时,按钮B按钮可以正常工作。
我看过很多游戏都没有遇到任何问题,但是现在我做不到。 > _<
我的游戏运作完美,我只想实现此选项,使其更易于管理。
以下是Sneaky按钮的实现代码:
-(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];
}
抱歉我的英语不好,我试着没有翻译:(
答案 0 :(得分:0)
将按钮上的claimsUserInteraction
属性设置为NO
。
来自CCResponder
的Cocos2D文档:
/**
* 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;