【发布时间】:2014-05-18 14:17:05
【问题描述】:
我在 iOS 设备上使用 Cocos2D 3.0。
在我的 HUD 类中,我有 4 个按钮(SneakyInput 库),左右 ButtonA 和 ButtonB,一切正常,但是当我移动手指(不抬起屏幕)时,按钮被按住。
现在发生的情况是,当我按下一个按钮并移动我的手指按钮时,直到您抬起手指为止。
我想要:
当我触摸 buttonA 并将手指移到 buttonB 时,buttonB 按钮起作用。
我见过很多游戏都可以毫无问题地实现这一点,但现在我做不到。 >_<.>
我的游戏运行良好,我只是想实现这个选项以使其更易于管理。
下面是 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];
}
对不起,我的英语不好,我在没有翻译的情况下尝试:(
【问题讨论】:
标签: ios objective-c cocos2d-iphone