0
我試圖在touchended方法檢測到第二次觸摸時將sprite上的不透明度設置爲零。COCOS2D:setOpacity = 0不起作用
其他的一切,如果聲明工作除了setOpacity部分。
出於某種原因,它不希望設置不透明度設爲零CCsprite
我究竟做錯了什麼?
- (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");
}
}
}
}
裏面的東西那三個else if語句越來越稱爲 – Chris
更新:如果我改變例如[animatingRubyglow3 setOpacity:0]; [animatingRuby3 setOpacity:0]; animatingRuby3是另一個CCSprite。那麼它工作正常。它只是animatingRubyglow1,animatingRubyglow2和animatingRubyglow3 CCSprites它不起作用將Opacity設置爲零 – Chris