Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to add an image to the scene, but it should just be added to the scene invisible, FadeIn and then be deleted when the effect finishes.

My problem is that the images blink once when they are added to the scene, then they do the intended effect. My best guess is that when they are added they show on the scene for a split second before starting the animation. I though of making them invisible for a split second before activating them, but I am not sure how to code it.

 const bool Sunbeams::add()
{
const CCSize kSceenSize = CCDirector::sharedDirector()->getWinSize();

const int nRayType = random( m_kRays.size());

const CCPoint kPosition( random( static_cast < int >( kSceenSize.width)),
                         0.0f);

const float fDuration = random( m_fDurationVariance) + m_fDurationMin;

CCSprite* pkLightBeam = CCSprite::spriteWithTexture( m_kRays[nRayType]);

if ( !pkLightBeam)
{
    msg::debug( "Sunbeams::add",
                "Failed to create sprite from ray '%d'!\n",
                m_kRays[nRayType]);

    return false;
}

pkLightBeam->setAnchorPoint( CCPointZero);

pkLightBeam->setPosition( kPosition);

m_kActiveBeams.push_back( pkLightBeam);

CCDirector::sharedDirector()->getRunningScene()->addChild( pkLightBeam);

CCActionInterval* pkAction = CCFadeIn::actionWithDuration( fDuration);

CCActionInterval* pkActionBack = pkAction->reverse();       

pkLightBeam->runAction( CCSequence::actions( pkAction,
                                             pkActionBack,
                                             0));

return true;
}
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

It was a problem with the alpha, the image was shown before the effect started

pkLightBeam->setOpacity( 0);

before adding it to the scene fixed it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.