Here is what I am trying to do: With the left joystick the player can steer the figure and with the right joystick it can attack. Problem is that the left joystick seems to get all the input, the right one does not even register anything. I enabled multipletouch after the eagleView and gone thoroughly over the code. But I seem to miss something. I initiliaze both sticks and it shows me both of them in game, but like I said, only the left one works.

I initialize them both. From the h. file:

SneakyJoystick *joystick;
SneakyJoystick *joystickRight;

And in m.file I synthesize, deallocate and initialize them. In order to use one for controlling and the other for attacking I put this:

andListOfGameObjects:(CCArray*)listOfGameObjects {

if ((self.characterState == kStateIdle) || 
    (self.characterState == kStateWalkingBack) ||
    (self.characterState == kStateWalkingLeft) ||
    (self.characterState == kStateWalkingRight)||
    (self.characterState == kStateWalkingFront) ||
    (self.characterState == kStateAttackingFront) ||
    (self.characterState == kStateAttackingBack)||
    (self.characterState == kStateAttackingRight)||
    (self.characterState == kStateAttackingLeft)) {

    if (joystick.degrees > 60 && joystick.degrees < 120) {
        if (self.characterState != kStateWalkingBack) 
            [self changeState:kStateWalkingBack];

    }else if (joystick.degrees > 1 && joystick.degrees < 59) {
            if (self.characterState != kStateWalkingRight) 
                [self changeState:kStateWalkingRight];

    } else if (joystick.degrees > 211 && joystick.degrees < 300) {
        if (self.characterState != kStateWalkingFront) 
            [self changeState:kStateWalkingFront];

    } else if (joystick.degrees > 301 && joystick.degrees < 360){
    if (self.characterState != kStateWalkingRight)
            [self changeState:kStateWalkingRight];

    } else if (joystick.degrees > 121 && joystick.degrees < 210) {
        if (self.characterState != kStateWalkingLeft)
            [self changeState:kStateWalkingLeft];

if (joystickRight.degrees > 60 && joystickRight.degrees < 120) {
    if (self.characterState != kStateAttackingBack) 
        [self changeState:kStateAttackingBack];

}else if (joystickRight.degrees > 1 && joystickRight.degrees < 59) {
    if (self.characterState != kStateAttackingRight) 
        [self changeState:kStateAttackingRight];

} else if (joystickRight.degrees > 211 && joystickRight.degrees < 300) {
    if (self.characterState != kStateAttackingFront) 
        [self changeState:kStateAttackingFront];

} else if (joystickRight.degrees > 301 && joystickRight.degrees < 360){
    if (self.characterState != kStateAttackingRight)
        [self changeState:kStateAttackingRight];

} else if (joystickRight.degrees > 121 && joystickRight.degrees < 210) {
    if (self.characterState != kStateAttackingLeft)
        [self changeState:kStateAttackingLeft];
        [self applyJoystick:joystick 
        [self applyJoystick:joystickRight 

Maybe it has something to do with putting them both to time delta? I tried working around it, but it did not work. So I am thankful for any input you guys can give me :)

As per Request here is some more code: This is from the init of my gameplaylayer.

self.isTouchEnabled = YES;
[knight setJoystick:leftJoystick];
[knight setJoystickRight:attackButton];

And also from the gameplaylayer method:

-(void)initJoystickAndButtons {
CGSize screenSize = [CCDirector sharedDirector].winSize;
CGRect joystickBaseDimensions = CGRectMake(0, 0, 128.0f, 128.0f);
CGRect attackButtonDimensions = CGRectMake(0, 0, 128.0f, 128.0f);
CGPoint joystickBasePosition;
CGPoint attackButtonPosition;
joystickBasePosition = ccp(screenSize.width*0.10f,
attackButtonPosition = ccp(screenSize.width*0.9f,

SneakyJoystickSkinnedBase *joystickBase =
[[[SneakyJoystickSkinnedBase alloc] init] autorelease];
joystickBase.position = joystickBasePosition;
joystickBase.backgroundSprite =
[CCSprite spriteWithFile:@"dpadDown.png"];
joystickBase.thumbSprite =
[CCSprite spriteWithFile:@"joystickDown.png"];

joystickBase.joystick = [[SneakyJoystick alloc]
leftJoystick = [joystickBase.joystick retain];
[self addChild:joystickBase];

SneakyJoystickSkinnedBase *attackButtonBase = [[[SneakyJoystickSkinnedBase
                                               alloc] init] autorelease];
attackButtonBase.position = attackButtonPosition;
attackButtonBase.backgroundSprite = [CCSprite spriteWithFile:
attackButtonBase.thumbSprite = [CCSprite

attackButtonBase.joystick = [[SneakyJoystick alloc] initWithRect:
attackButton = [joystickBase.joystick retain];
[self addChild:attackButtonBase];

And I added this in the appdelegate

glView.multipleTouchEnabled = YES;

I went over the whole code today, only to (after way too long) spot one mistake, that did it all.

leftJoystick = [joystickBase.joystick retain];
attackButton = [joystickBase.joystick retain];

It actually has to be

attackButton = [attackButtonBase.joystick retain];

and it works now. Always the little things that drive you crazy...

| improve this answer | |

Putting them both to delta shouldn't matter, as you say one works already I take it you've enable touches in the init method.

Could you post your touch methods please? Not only you do you need to enable touch you should probably make sure you're using

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

Instead of cctouch. I think the problem may lie with how you handle the code in the above methods, if you edit your question with that code, then people maybe able to help you a little more.


I see you're using sneaky joystick. I think that this maybe outdated now, as it was last updated around 2010. Take a look at this repository its a lot cleaner and easier to implement, there will be no need for really long if statements as you can move your sprite using three joystick delegates:




Have you set multitouch available on EAGLView?

After you've initialized EAGLView add:

view.multipleTouchEnabled = YES;
| improve this answer | |
  • \$\begingroup\$ Thanks for your contribution, I added the code in question. \$\endgroup\$ – Blade Jun 24 '12 at 15:33
  • \$\begingroup\$ I've updated my answer. \$\endgroup\$ – Lewis Jun 24 '12 at 18:27
  • \$\begingroup\$ Thanks. I will look into it and post if it worked, tomorrow. :) \$\endgroup\$ – Blade Jun 24 '12 at 18:58
  • \$\begingroup\$ As of now it doesn't work. But I will try a few things and then get back to you. \$\endgroup\$ – Blade Jun 25 '12 at 15:50
  • \$\begingroup\$ Problem is the same with zJoystick, even more to be honest. Ill stay with SneakyJoystick. There must be a way to get it to work with it. \$\endgroup\$ – Blade Jun 25 '12 at 16:22

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.