Cocos2d iphone COCOS2D:setOpacity=0不';行不通

Cocos2d iphone COCOS2D:setOpacity=0不';行不通,cocos2d-iphone,opacity,Cocos2d Iphone,Opacity,当touchended方法检测到第二次触摸时,我试图将精灵的不透明度设置为零 if语句中除setOpacity部分外的所有其他部分都有效 出于某种原因,它不希望将CCsprite的不透明度设置为零 我做错了什么 - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *) event{ //state = kRubyStateUngrabbed; CGSize screenSize = [[CCDirector sharedDirect

当touchended方法检测到第二次触摸时,我试图将精灵的不透明度设置为零

if语句中除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");  
        }
    }
}

}

您是否通过设置断点来检查是否实际调用了带有setOpacity的行?如果你不知道怎么做

设置if/else if子句的方法仅在触摸位置在
animatingRuby3
touch==self.RubySecondTouch
的边界框上为而不是时才会运行该特定代码。从这些变量的名称推断,这似乎没有什么意义,也许这两个条件永远不会成立

以下代码简化为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 ...
    }
}

这三条if语句中的其他所有内容都被调用为dupdate:如果我更改了[animatingRubyglow3 setOpacity:0];至[动画Ruby3设置不透明度:0];动画Ruby3是另一个CCSprite。那么它工作得很好。只是动画RubyGlow1、动画RubyGlow2和动画RubyGlow3 CCSprites无法将不透明度设置为零