cocos2d-x 翻转卡牌 效果 动画 flip card effect
//*** .h 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) if (action->init(duration,startAngle,dstAngle,depth)) { return action; } return nullptr; } FakeRotateY* FakeRotateY::create(float duration,float dstAngle) bool FakeRotateY::init(float duration,float depth) target_ = nullptr; return true; } return false; } void FakeRotateY::startWithTarget(Node *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 solution CCASSERT(target_,"this action can be used only with sprite"); } void FakeRotateY::update(float time) 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |