Reputation: 1
I'm trying to set the opacity to zero on a sprite when the touchended method detects a second touch on it.
everything else in that if statement works except the setOpacity part.
For some reason it doesn't want to set the Opacity to zero for the CCsprite
what am I doing wrong?
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *) event{
//state = kRubyStateUngrabbed;
CGSize screenSize = [[CCDirector sharedDirector] winSize];
animatingRuby1.anchorPoint = ccp( 0.5, 0.5 );
animatingRuby2.anchorPoint = ccp( 0.5, 0.5 );
animatingRuby3.anchorPoint = ccp( 0.5, 0.5 );
//Animating the glow of the rubies
animatingRubyglow1 = [CCSprite spriteWithFile:@"rubinglow.png"];
[animatingRubyglow1 setPosition: CGPointMake(screenSize.width/1.186f, screenSize.height*0.17f)];
[animatingRubyglow1 setScaleX:screenSize.width/10850.0f];
[animatingRubyglow1 setScaleY:screenSize.height/7552.0f];
animatingRubyglow2 = [CCSprite spriteWithFile:@"rubinglow.png"];
[animatingRubyglow2 setPosition: CGPointMake(screenSize.width/1.105f, screenSize.height*0.17f)];
[animatingRubyglow2 setScaleX:screenSize.width/10850.0f];
[animatingRubyglow2 setScaleY:screenSize.height/7552.0f];
animatingRubyglow3 = [CCSprite spriteWithFile:@"rubinglow.png"];
[animatingRubyglow3 setPosition: CGPointMake(screenSize.width/1.035f, screenSize.height*0.17f)];
[animatingRubyglow3 setScaleX:screenSize.width/10850.0f];
[animatingRubyglow3 setScaleY:screenSize.height/7552.0f];
id EaseIn = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:0.89 scaleX:0.08f scaleY:0.08f] rate:12.0];
id EaseOut = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:0.89 scaleX:0.12f scaleY:0.12f] rate:12.0];
id action = [CCSequence actions:EaseOut,EaseIn, nil];
CGPoint location = [self convertTouchToNodeSpace: touch];
if(allowTouchRuby){
//If Rubies are touched for the 1st time then activate the bricks and let the ruby that has been touch bounch
if (touch == self.RubyFirstTouch) {
if(CGRectContainsPoint([animatingRuby1 boundingBox], location)){
if(PulsatingAnimeRuby2 == NO && PulsatingAnimeRuby3 == NO){
Repaction1 = [CCRepeatForever actionWithAction: action];
PulsatingAnimeRuby1 = YES;
CCLOG(@"animatingRuby1 1st time");
[self ActivatedBricks:PulsatingAnimeRuby1];
[self addChild:animatingRubyglow1 z:4];
[animatingRubyglow1 runAction:Repaction1];
[animatingRubyglow1 setOpacity: 150];
}
}
if(CGRectContainsPoint([animatingRuby2 boundingBox], location)){
if(PulsatingAnimeRuby1 == NO && PulsatingAnimeRuby3 == NO){
Repaction2 = [CCRepeatForever actionWithAction: action];
PulsatingAnimeRuby2 = YES;
CCLOG(@"animatingRuby2 1st time");
[self ActivatedBricks:PulsatingAnimeRuby2];
[self addChild:animatingRubyglow2 z:4];
[animatingRubyglow2 runAction:Repaction2];
[animatingRubyglow2 setOpacity: 150];
}
}
if(CGRectContainsPoint([animatingRuby3 boundingBox], location)){
if(PulsatingAnimeRuby1 == NO && PulsatingAnimeRuby2 == NO){
Repaction3 = [CCRepeatForever actionWithAction: action];
PulsatingAnimeRuby3 = YES;
CCLOG(@"animatingRuby3 1st time");
[self ActivatedBricks:PulsatingAnimeRuby3];
[self addChild:animatingRubyglow3 z:4];
[animatingRubyglow3 runAction:Repaction3];
[animatingRubyglow3 setOpacity: 150];
}
}
}
//Else return the rubys to their original size and stop the action
else if (touch == self.RubySecondTouch) {
//if(PulsatingAnimeRuby1 == YES){
if(PulsatingAnimeRuby1){
[animatingRubyglow1 stopAction:Repaction1];
animatingRubyglow1.opacity = 0; //Doesn't work
//[animatingRubyglow1 setOpacity:0];
PulsatingAnimeRuby1 = NO;
[self ActivatedBricks:PulsatingAnimeRuby1];
CCLOG(@"animatingRuby1 2st time");
}
//else if(PulsatingAnimeRuby2 == YES){
else if(PulsatingAnimeRuby2){
[animatingRubyglow2 stopAction:Repaction2];
animatingRubyglow2.opacity = 0; //Doesn't work
//[animatingRubyglow2 setOpacity:0];
PulsatingAnimeRuby2 = NO;
[self ActivatedBricks:PulsatingAnimeRuby2];
CCLOG(@"animatingRuby2 2st time");
}
//else if(PulsatingAnimeRuby3 == YES){
else if(PulsatingAnimeRuby3){
[animatingRubyglow3 stopAction:Repaction3];
animatingRubyglow3.opacity = 0; //Doesn't work
//[animatingRubyglow3 setOpacity:0];
PulsatingAnimeRuby3 = NO;
[self ActivatedBricks:PulsatingAnimeRuby3];
CCLOG(@"animatingRuby3 2st time");
}
}
}
}
Upvotes: 0
Views: 1564
Reputation: 64477
Have you checked by setting a breakpoint that the line with setOpacity actually gets called? Read this article if you don't know how to do that.
The way you setup the if/else if clauses will only run that particular code if the touch location is not on the boundingBox of animatingRuby3
AND touch == self.RubySecondTouch
. Inferring from the names of these variables it seems that this makes little sense and perhaps these two conditions will never be true?
Here's the code reduced to just the if statements:
if(CGRectContainsPoint([animatingRuby3 boundingBox], location)){
}
//Else return the rubys to their original size and stop the action
else if (touch == self.RubySecondTouch) {
if(PulsatingAnimeRuby1){
// opacity is set here ...
}
}
Upvotes: 1