创建JumpTo和JumpBy的实例时,第一个参数是动作时间间隔,第二参数是位置坐标,第三个参数是跳跃高度,第四个参数是跳跃的次数,两者的区别是前者是跳跃到位置坐标,而后者是在当前位置的基础上跳跃位置坐标的距离
JumpActionScene.cpp
#include"JumpActionScene.h"
Scene* JumpAction::createScene(){
auto scene = Scene::create();
auto layer = JumpAction::create();
scene->addChild(layer);
return scene;
}
bool JumpAction::init(){
if (!Layer::init()){
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
auto ball = Sprite::create("ball.png");
ball->setPosition(Point(ball->getContentSize().width / 2, visibleSize.height / 2));
this->addChild(ball);
auto jumpTo = JumpTo::create(5.0, Point(860, 320), 50, 2);
ball->runAction(jumpTo);
auto ball1 = Sprite::create("ball.png");
ball1->setPosition(Point(ball->getContentSize().width / 2, visibleSize.height / 2));
this->addChild(ball1);
auto jumpBy = JumpBy::create(5.0, Point(860, 320), 50, 2);
ball1->runAction(jumpBy);
return true;
}
本文介绍如何使用Cocos2d-x中的JumpTo和JumpBy动作来创建动画效果。这两种动作允许开发者轻松地为游戏元素添加跳跃行为,通过调整时间间隔、位置坐标、跳跃高度和次数等参数,可以灵活地控制动画的表现形式。
1715

被折叠的 条评论
为什么被折叠?



