Image with FadeIn effect blinks when added to scene
Posted
by
Ef Es
on Game Development
See other posts from Game Development
or by Ef Es
Published on 2012-06-27T13:20:18Z
Indexed on
2012/06/27
15:27 UTC
Read the original article
Hit count: 369
cocos2d-x
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;
}
© Game Development or respective owner