Using two joysticks in Cocos2D
Posted
by
Blade
on Game Development
See other posts from Game Development
or by Blade
Published on 2012-06-22T10:04:23Z
Indexed on
2012/06/22
15:25 UTC
Read the original article
Hit count: 274
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 :)
© Game Development or respective owner