Hi Guys,
I have one bug remaining in my game. Every now and then the main button I use to fire a laser sticks (stays stuck on) even after moving my finger off of it or removing my finger from the screen. This is a graphic/using targeted touches, not anything to do with the cocos2d menu code.
Here's how I do things:
@implementation BoostButton
@synthesize radius = _radius;
@synthesize isPressed = _isPressed;
@synthesize availableBoost = _availableBoost;
@synthesize boostDuration = _boostDuration;
-(void)onEnter
{
[super onEnter];
_radius = self.contentSize.width / 2.0f;
_isPressed = NO;
_availableBoost = 0.0f;
_boostDuration = 0.0f;
[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
-(void)onExit
{
[[TouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
InGameLayer *pGameLayer = ((InGameMode *)([ModeManager instance].pCurrMode)).pInGameLayer;
cpVect cpvTouchPt = [[Director sharedDirector] convertToGL:[touch locationInView:[touch view]]];
if (ccpDistance([self position], cpvTouchPt) <= _radius)
{
if ((_availableBoost == 0.0f) || [pGameLayer tiltInteractionEnabled])
{
[[SimpleAudioEngine sharedEngine] playEffect:@"Assets/Audio/BoostCannonCannotFire.caf"];
}
_isPressed = YES;
return YES;
}
return NO;
}
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
cpVect cpvTouchPt = [[Director sharedDirector] convertToGL:[touch locationInView:[touch view]]];
if (ccpDistance([self position], cpvTouchPt) > [self radius])
{
_isPressed = NO;
}
}
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
_isPressed = NO;
}
-(void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
_isPressed = NO;
}
@end
I am sure that the way I use the isPressed property in the rest of my code is ok. Any ideas? My other game code simply does something like this:
if ([_pBoostButton isPressed] && ([_pBoostButton availableBoost] > 0.0f) && !_tiltInteractionEnabled && !_gameHasEnded)
{
turnLaserOnIfIt'sNotOnAlready
}
else
{
turnLaserOffIfIt'sNotOffAlready
}
Thanks For Your Thoughts,
Jason