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;