cocos2d-x 3.x学习之JumpAction

本文介绍如何使用Cocos2d-x中的JumpTo和JumpBy动作来创建动画效果。这两种动作允许开发者轻松地为游戏元素添加跳跃行为,通过调整时间间隔、位置坐标、跳跃高度和次数等参数,可以灵活地控制动画的表现形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值