cocos2dx 3.2版本。。。
class TScale:public cocos2d ::ScaleTo{
public:
TScale(void);
~TScale(void);
static TScale* actionWithDuration(float duration,float scale);
virtual void startWithTarget(Node *target);
virtual void update(float time);
void removeTaget(Node *node);
private:
float alreadyTime;
};
```
TScale::TScale(void)
{
}
TScale::~TScale(void)
{
}
TScale* TScale::actionWithDuration(float duration, float scale){
TScale *ts=new TScale();
ts->create(duration, scale);
return ts;
};
void TScale::startWithTarget(cocos2d::Node *target){
this->setTarget(target);
this->alreadyTime=0;
}
void TScale::update(float time){
if(this->getTarget()!=NULL){
this->getTarget()->setScaleX(_startScaleX+_deltaX*time);
this->getTarget()->setScaleY(_startScaleY+_deltaY*time);
this->alreadyTime+=time*this->getDuration();
if(this->alreadyTime>0.5 && time>0.5){
this->alreadyTime=0;
Sprite *_clearSprite=Sprite::create("Star1.png");
_clearSprite->setAnchorPoint(this->getTarget()->getAnchorPoint());
_clearSprite->setPosition(this->getTarget()->getPosition());
_clearSprite->setScale(this->getTarget()->getScale());
_clearSprite->setOpacity(this->getTarget()->getOpacity());
this->getTarget()->getParent()->addChild(_clearSprite);
Sequence *sequence=Sequence::create(FadeTo::create(0.2, 0),
CC_CALLBACK_1(TScale::removeTaget, this->getTarget()->getParent()),NULL);
_clearSprite->runAction(sequence);
}
}
}
void TScale::removeTaget(Node *node){
node->removeFromParentAndCleanup(true);
}
```