COCOS2D:setOpacity = 0不起作用

时间:2011-11-14 05:57:27

标签: cocos2d-iphone opacity

我试图在精灵方法检测到第二次触摸时在精灵上将不透明度设置为零。

除了setOpacity部分之外,if语句中的所有其他内容都可用。

出于某种原因,它不希望将CCacity的Opacity设置为零

我做错了什么?

- (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");  
        }
    }
}

}

1 个答案:

答案 0 :(得分:1)

您是否通过设置断点来检查实际调用了setOpacity的行? Read this article如果您不知道该怎么做。

如果animatingRuby3touch == self.RubySecondTouch的边界框上的触摸位置不是,则设置if / else if子句的方式只会运行该特定代码。从这些变量的名称推断出来似乎没什么意义,也许这两个条件永远不会成真?

这里的代码简化为if语句:

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 ...
    }
}