mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5463 from andyque/refactor3877
closed #3877. make fadeIn and fadeOut behaviours correct
This commit is contained in:
commit
4277509966
|
@ -1664,7 +1664,7 @@ FadeIn* FadeIn::create(float d)
|
||||||
{
|
{
|
||||||
FadeIn* action = new FadeIn();
|
FadeIn* action = new FadeIn();
|
||||||
|
|
||||||
action->initWithDuration(d);
|
action->initWithDuration(d,255.0f);
|
||||||
action->autorelease();
|
action->autorelease();
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
@ -1674,25 +1674,42 @@ FadeIn* FadeIn::clone() const
|
||||||
{
|
{
|
||||||
// no copy constructor
|
// no copy constructor
|
||||||
auto a = new FadeIn();
|
auto a = new FadeIn();
|
||||||
a->initWithDuration(_duration);
|
a->initWithDuration(_duration,255.0f);
|
||||||
a->autorelease();
|
a->autorelease();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FadeIn::update(float time)
|
void FadeIn::setReverseAction(cocos2d::FadeTo *ac)
|
||||||
{
|
{
|
||||||
if (_target)
|
_reverseAction = ac;
|
||||||
{
|
|
||||||
_target->setOpacity((GLubyte)(255 * time));
|
|
||||||
}
|
|
||||||
/*_target->setOpacity((GLubyte)(255 * time));*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionInterval* FadeIn::reverse() const
|
|
||||||
|
FadeTo* FadeIn::reverse() const
|
||||||
{
|
{
|
||||||
return FadeOut::create(_duration);
|
auto action = FadeOut::create(_duration);
|
||||||
|
action->setReverseAction(const_cast<FadeIn*>(this));
|
||||||
|
return action;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FadeIn::startWithTarget(cocos2d::Node *target)
|
||||||
|
{
|
||||||
|
ActionInterval::startWithTarget(target);
|
||||||
|
|
||||||
|
if (nullptr != _reverseAction) {
|
||||||
|
this->_toOpacity = this->_reverseAction->_fromOpacity;
|
||||||
|
}else{
|
||||||
|
_toOpacity = 255.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target) {
|
||||||
|
_fromOpacity = target->getOpacity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// FadeOut
|
// FadeOut
|
||||||
//
|
//
|
||||||
|
@ -1701,7 +1718,7 @@ FadeOut* FadeOut::create(float d)
|
||||||
{
|
{
|
||||||
FadeOut* action = new FadeOut();
|
FadeOut* action = new FadeOut();
|
||||||
|
|
||||||
action->initWithDuration(d);
|
action->initWithDuration(d,0.0f);
|
||||||
action->autorelease();
|
action->autorelease();
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
@ -1711,23 +1728,37 @@ FadeOut* FadeOut::clone() const
|
||||||
{
|
{
|
||||||
// no copy constructor
|
// no copy constructor
|
||||||
auto a = new FadeOut();
|
auto a = new FadeOut();
|
||||||
a->initWithDuration(_duration);
|
a->initWithDuration(_duration,0.0f);
|
||||||
a->autorelease();
|
a->autorelease();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FadeOut::update(float time)
|
void FadeOut::startWithTarget(cocos2d::Node *target)
|
||||||
{
|
{
|
||||||
if (_target)
|
ActionInterval::startWithTarget(target);
|
||||||
{
|
|
||||||
_target->setOpacity(GLubyte(255 * (1 - time)));
|
if (nullptr != _reverseAction) {
|
||||||
}
|
_toOpacity = _reverseAction->_fromOpacity;
|
||||||
/*_target->setOpacity(GLubyte(255 * (1 - time)));*/
|
}else{
|
||||||
|
_toOpacity = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionInterval* FadeOut::reverse() const
|
if (target) {
|
||||||
|
_fromOpacity = target->getOpacity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FadeOut::setReverseAction(cocos2d::FadeTo *ac)
|
||||||
{
|
{
|
||||||
return FadeIn::create(_duration);
|
_reverseAction = ac;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FadeTo* FadeOut::reverse() const
|
||||||
|
{
|
||||||
|
auto action = FadeIn::create(_duration);
|
||||||
|
action->setReverseAction(const_cast<FadeOut*>(this));
|
||||||
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -707,53 +707,6 @@ private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(Blink);
|
CC_DISALLOW_COPY_AND_ASSIGN(Blink);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255.
|
|
||||||
The "reverse" of this action is FadeOut
|
|
||||||
*/
|
|
||||||
class CC_DLL FadeIn : public ActionInterval
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** creates the action */
|
|
||||||
static FadeIn* create(float d);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Overrides
|
|
||||||
//
|
|
||||||
virtual void update(float time) override;
|
|
||||||
virtual FadeIn* clone() const override;
|
|
||||||
virtual ActionInterval* reverse(void) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
FadeIn() {}
|
|
||||||
virtual ~FadeIn() {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(FadeIn);
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0.
|
|
||||||
The "reverse" of this action is FadeIn
|
|
||||||
*/
|
|
||||||
class CC_DLL FadeOut : public ActionInterval
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** creates the action */
|
|
||||||
static FadeOut* create(float d);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Overrides
|
|
||||||
//
|
|
||||||
virtual void update(float time) override;
|
|
||||||
virtual FadeOut* clone() const override;
|
|
||||||
virtual ActionInterval* reverse(void) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
FadeOut() {}
|
|
||||||
virtual ~FadeOut() {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(FadeOut);
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
|
/** @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
|
||||||
@warning This action doesn't support "reverse"
|
@warning This action doesn't support "reverse"
|
||||||
|
@ -780,11 +733,64 @@ protected:
|
||||||
|
|
||||||
GLubyte _toOpacity;
|
GLubyte _toOpacity;
|
||||||
GLubyte _fromOpacity;
|
GLubyte _fromOpacity;
|
||||||
|
friend class FadeOut;
|
||||||
|
friend class FadeIn;
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(FadeTo);
|
CC_DISALLOW_COPY_AND_ASSIGN(FadeTo);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255.
|
||||||
|
The "reverse" of this action is FadeOut
|
||||||
|
*/
|
||||||
|
class CC_DLL FadeIn : public FadeTo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** creates the action */
|
||||||
|
static FadeIn* create(float d);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Overrides
|
||||||
|
//
|
||||||
|
virtual void startWithTarget(Node *target) override;
|
||||||
|
virtual FadeIn* clone() const override;
|
||||||
|
virtual FadeTo* reverse(void) const override;
|
||||||
|
|
||||||
|
void setReverseAction(FadeTo* ac);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
FadeIn():_reverseAction(nullptr) {}
|
||||||
|
virtual ~FadeIn() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CC_DISALLOW_COPY_AND_ASSIGN(FadeIn);
|
||||||
|
FadeTo* _reverseAction;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0.
|
||||||
|
The "reverse" of this action is FadeIn
|
||||||
|
*/
|
||||||
|
class CC_DLL FadeOut : public FadeTo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** creates the action */
|
||||||
|
static FadeOut* create(float d);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Overrides
|
||||||
|
//
|
||||||
|
virtual void startWithTarget(Node *target) override;
|
||||||
|
virtual FadeOut* clone() const override;
|
||||||
|
virtual FadeTo* reverse(void) const override;
|
||||||
|
|
||||||
|
void setReverseAction(FadeTo* ac);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
FadeOut():_reverseAction(nullptr) {}
|
||||||
|
virtual ~FadeOut() {}
|
||||||
|
private:
|
||||||
|
CC_DISALLOW_COPY_AND_ASSIGN(FadeOut);
|
||||||
|
FadeTo* _reverseAction;
|
||||||
|
};
|
||||||
/** @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
|
/** @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
|
||||||
@warning This action doesn't support "reverse"
|
@warning This action doesn't support "reverse"
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
|
|
|
@ -647,9 +647,13 @@ void ActionFade::onEnter()
|
||||||
|
|
||||||
auto action2 = FadeOut::create(1.0f);
|
auto action2 = FadeOut::create(1.0f);
|
||||||
auto action2Back = action2->reverse();
|
auto action2Back = action2->reverse();
|
||||||
|
auto action2BackReverse = action2Back->reverse();
|
||||||
|
auto action2BackReverseReverse = action2BackReverse->reverse();
|
||||||
|
|
||||||
|
_tamara->setOpacity(122);
|
||||||
_tamara->runAction( Sequence::create( action1, action1Back, NULL));
|
_tamara->runAction( Sequence::create( action1, action1Back, NULL));
|
||||||
_kathia->runAction( Sequence::create( action2, action2Back, NULL));
|
_kathia->setOpacity(122);
|
||||||
|
_kathia->runAction( Sequence::create( action2, action2Back,action2BackReverse,action2BackReverseReverse, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ActionFade::subtitle() const
|
std::string ActionFade::subtitle() const
|
||||||
|
|
Loading…
Reference in New Issue