cocos2d-x 3.x学习之JumpAction

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值