cocos2d-x 翻转卡牌 效果 动画 flip card effect

cocos2d-x 翻转卡牌 效果 动画 flip card effect,第1张

概述//*** .h class FakeRotateY : public cocos2d::RotateTo { public: /* creates the action / static FakeRotateY* create(float duration, float startAngle, float dstAngle, float depth); /* creates the action

//*** .h
class FakeRotateY : public cocos2d::Rotateto
{
public:
/* creates the action /
static FakeRotateY* create(float duration,float startAngle,float dstAngle,float depth);
/* creates the action with default dept = 6 /
static FakeRotateY* create(float duration,float dstAngle);
/* initializes the action /
bool init(float duration,float depth);

virtual ~FakeRotateY() {}

protected:

virtual voID startWithTarget(cocos2d::Node *target);virtual voID update(float time);

private:

float startAngle_;float dstAngle_;float diffAngle_;float radius_;float depth_;cocos2d::Sprite *target_;

};

//**** .cpp

FakeRotateY* FakeRotateY::create(float duration,float depth)
{
FakeRotateY *action = new (std::nothrow) FakeRotateY();
action->autorelease();

if (action->init(duration,startAngle,dstAngle,depth)) {    return action;}return nullptr;

}

FakeRotateY* FakeRotateY::create(float duration,float dstAngle)
{
//create instance with default depth = 6
return create(duration,6.0);
}

bool FakeRotateY::init(float duration,float depth)
{
if (Rotateto::initWithDuration(duration,dstAngle)) {
startAngle_ = startAngle;
dstAngle_ = dstAngle;
depth_ = depth;

target_ = nullptr;    return true;}return false;

}

voID FakeRotateY::startWithTarget(Node *target)
{
Rotateto::startWithTarget(target);

radius_ = target->getContentSize().wIDth / 2.0;calculateAngles(startAngle_,diffAngle_,dstAngle_);target_ = dynamic_cast<Sprite *>(target); //dynamic_cast maybe overhead,but this action works only with Sprites. todo: find better solutionCCASSERT(target_,"this action can be used only with sprite");

}

voID FakeRotateY::update(float time)
{
polygonInfo pi = target_->getpolygonInfo();

pi.triangles.verts[0].vertices.x = cosf(M_PI + CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_ + radius_;pi.triangles.verts[0].vertices.y = (sinf(M_PI + CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_) / depth_ + target_->getContentSize().height;pi.triangles.verts[1].vertices.x = cosf(M_PI - CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_ + radius_;pi.triangles.verts[1].vertices.y = (sinf(M_PI - CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_) / depth_;pi.triangles.verts[2].vertices.x = cosf(CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_ + radius_;pi.triangles.verts[2].vertices.y = (sinf(CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_) / depth_ + target_->getContentSize().height;pi.triangles.verts[3].vertices.x = cosf(-CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_ + radius_;pi.triangles.verts[3].vertices.y = (sinf(-CC_degrees_TO_radians(startAngle_ + diffAngle_*time)) * radius_) / depth_;target_->setpolygonInfo(pi);

}

//author
https://github.com/MrCapone/cocos2d-x-custom-actions
Demo: https://www.dropbox.com/s/64y0uuj02quextl/cards.webm21

总结

以上是内存溢出为你收集整理的cocos2d-x 翻转卡牌 效果 动画 flip card effect全部内容,希望文章能够帮你解决cocos2d-x 翻转卡牌 效果 动画 flip card effect所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1079719.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存