I've added a joystick to my iOS game using the latest SneakyInput joystick code for cocos2d v3. It works well, but when a CCButton I have is pressed, the joystick touch event ends.

Based on my research, I've already set multitouch:

[CCDirector sharedDirector].view.multipleTouchEnabled = YES;

I've even tried setting multipleTouchEnabled for every button/joystick node, but still nothing works. Every time I touch the button, the joystick touchEnded method is called.

Here's the joystick code:

leftJoy = [[SneakyJoystickSkinnedBase alloc] init];
leftJoy.position = ccp(96,96);
leftJoy.backgroundSprite = [ColoredCircleSprite circleWithColor:[CCColor colorWithCcColor4b: ccc4(21, 21, 21, 127)] radius:64];
leftJoy.thumbSprite = [CCSprite spriteWithImageNamed:@"joystick.png"];
leftJoy.joystick = [[SneakyJoystick alloc] initWithRect:CGRectMake(0,0,128,128)];
leftJoy.joystick.multipleTouchEnabled = YES; // just testing
leftJoy.multipleTouchEnabled = YES; // just testing
[self addChild:leftJoy];

And my button code:

fire = [CCButton
                  spriteFrame:[CCSpriteFrame frameWithImageNamed:@"fire-enabled.png"]
                  highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"fire-active.png"]
                  disabledSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"fire.png"]];
fire.position = ccp(x,y);
fire.multipleTouchEnabled = YES; // testing
[fire setTarget:[World sharedWorld].player selector:@selector(fire:)];
[self addChild:fire];

The joystick works fine. Until the fire button is pressed.

I could redesign my buttons to use the sneakyinput button, but they work fine as-is except for this one issue.

  • \$\begingroup\$ Can you provide the whole sneakyjoy class ? Hard to tell. Maybe the problem is in there. \$\endgroup\$ – user1033882 Aug 11 '14 at 18:18
  • \$\begingroup\$ Try this, in your main scene that loads the interface: [CCDirector sharedDirector].view.multipleTouchEnabled = YES; \$\endgroup\$ – user1033882 Aug 12 '14 at 9:08

Use CCSprite instead of CCButton.

Handle every CCSprite touch event in TouchDelegate method.

Inherite class where you are using SneakyInput joystick by CCLayer with Touch Enable.

Link : https://github.com/sneakyness/SneakyInput

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.