COCOS2D: setOpacity = 0 не работает - PullRequest
0 голосов
/ 14 ноября 2011

Я пытаюсь установить непрозрачность на ноль для спрайта, когда метод 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");  
        }
    }
}

}

1 Ответ

1 голос
/ 14 ноября 2011

Вы установили контрольную точку, что на самом деле вызывается строка с setOpacity? Прочтите эту статью , если вы не знаете, как это сделать.

Способ настройки предложений if / else if будет запускать этот конкретный код только в том случае, если местоположение касания не в ограничивающем поле animatingRuby3 AND 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 ...
    }
}
...