
Interestingly enough, I found that the SneakyInput registers a button tap twice or more in tests. This seems to be attributed to a very quick frame rate.
I have a frame rate that stays between 60 and 58. So, while my finger is pressed on a jump or fire button the game has cycled through a couple frames.
I noticed that when a button is pressed the value is equal to 1.
dpad.attackButton.value == 1;
This allowed me to come up with the fix below.
@interface HelloWorldLayer : CCLayer
{
MyJoystick *dpad;
BOOL freeToAttack, freeToJump;
}
I add two boolean variables to tell me when the button is free to fire or free to jump. This means that once a button is pressed it is registered as not free or false.
if ( dpad.jumpButton.value == 0 )
freeToJump = YES;
and
if ( dpad.attackButton.value == 0 )
freeToAttack = YES;
Then I do a quick check to make sure that the button value has reverted back to zero, which signifies the button is free to be pressed again.
if ( dpad.jumpButton.value == 0 ) freeToJump = YES;
if ( dpad.jumpButton.value == 1 && freeToJump ) {
freeToJump = NO;
CCLOG(@"Jump button pressed");
}
if ( dpad.attackButton.value == 0 ) freeToAttack = YES;
if ( dpad.attackButton.value == 1 && freeToAttack ) {
freeToAttack = NO;
CCLOG(@"Attack button pressed");
}
The code above checks that the button value is 0 and that the button is free to be pressed, allowing my button press code to be run.
Conclusion
Although, it is not an optimal situation, it is a fix for the problem at hand.


