2
\$\begingroup\$

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:

-(void)updateStateWithDeltaTime:(ccTime)deltaTime
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 
               forTimeDelta:deltaTime];
        [self applyJoystick:joystickRight 
               forTimeDelta:deltaTime];
}

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,
                           screenSize.height*0.15f);
attackButtonPosition = ccp(screenSize.width*0.9f,
                          screenSize.height*0.15f);

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]
                         initWithRect:joystickBaseDimensions];
leftJoystick = [joystickBase.joystick retain];
[self addChild:joystickBase];

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

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

And I added this in the appdelegate

glView.multipleTouchEnabled = YES;
\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

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...

\$\endgroup\$
2
\$\begingroup\$

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.

Update:

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:

-(void)joystickControlBegan;
-(void)joystickControlMoved;
-(void)joystickControlEnded;

https://github.com/zaldzbugz/zJoystick

EDIT:

Have you set multitouch available on EAGLView?

After you've initialized EAGLView add:

view.multipleTouchEnabled = YES;
\$\endgroup\$
6
  • \$\begingroup\$ Thanks for your contribution, I added the code in question. \$\endgroup\$
    – Blade
    Commented Jun 24, 2012 at 15:33
  • \$\begingroup\$ I've updated my answer. \$\endgroup\$
    – Lewis
    Commented Jun 24, 2012 at 18:27
  • \$\begingroup\$ Thanks. I will look into it and post if it worked, tomorrow. :) \$\endgroup\$
    – Blade
    Commented Jun 24, 2012 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
    Commented Jun 25, 2012 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
    Commented Jun 25, 2012 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .