创建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;
}