I want to know if there is a way to create a fadeIn animation which begins from a certain value of opacity greater than 0. Default fadeIn animation modifies the opacity from 0 to 255, but I need an animation that goes from 10 to 255 for example.
Ok I found a way by extending the CCFadeIn class and overriding the update() method
class CCFadeInRange : public CCFadeIn
{
public:
CCFadeInRange(int from, int to) : from(from), to(to){};
virtual void update(float time);
/** creates the action */
static CCFadeInRange* create(float d, int from, int to);
private:
int from;
int to;
};
CCFadeInRange* CCFadeInRange::create(float d, int from, int to)
{
CCFadeInRange* pAction = new CCFadeInRange(from, to);
pAction->initWithDuration(d);
pAction->autorelease();
return pAction;
}
//CCFadeIn with range
void CCFadeInRange::update(float time)
{
CCRGBAProtocol *pRGBAProtocol = dynamic_cast(m_pTarget);
if (pRGBAProtocol)
{
pRGBAProtocol->setOpacity(from + (GLubyte)((to - from) * time));
}
}
You should use CCFadeTo : “It modifies the opacity from the current value to a custom one.”
Set the opacity to 10, then fade to 255.
You’re right, i should use that, thx