Reputation: 275
I'm trying to set alpha of a SKNode
every time it is clicked either to 0 or 1. My code currently turns it off but won't turn it back on. Any idea why?
- (void)handleTouchedPoint:(CGPoint)touchedPoint {
touchedNode = [self nodeAtPoint:touchedPoint];
// Detects which node was touched by utilizing names.
if ([touchedNode.name isEqualToString:@"play"]) {
isOnPlay = true;
NSLog(@"Touched play");
}
if ([touchedNode.name isEqualToString:@"light1"]) {
//NSLog(@"%.2f", touchedNode.alpha);
if(touchedNode.alpha != 0.0)
{
NSLog(@"Off");
touchedNode.alpha = 0.0;
//[touchedNode setAlpha:0.0];
}
else{
NSLog(@"On");
touchedNode.alpha = 1.0;
//[touchedNode setAlpha:1.0];
}
NSLog(@"Touched light");
}
}
Upvotes: 0
Views: 48
Reputation: 21893
You might be running into the famous float rounding issue. Use debug and check the values. The alpha might not be exactly zero.
Upvotes: 1