位置: 编程技术 - 正文

cocos2dx 3.x 动作的认识(cocos2d动画)

编辑:rootadmin
1. MoveTo 和 MoveBy

推荐整理分享cocos2dx 3.x 动作的认识(cocos2d动画),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:cocos-2dx,cocos动效,cocos2dx动画,cocos2dx动画,cocos2d 3d,cocos2dx视频教程,cocos2d动画,cocos2d动画,内容如对您有帮助,希望把文章链接给更多的朋友!

MoveTo 就是移动到指定坐标的一个动作。

MoveTo::create(float duration, const Vec2& deltaPosition)

float duration :动作执行持续时间,单位为秒。

const Vec2& deltaPosition:指定移动的目的坐标。

MoveBy就是移动距离

MoveBy::create(float duration, const Vec2& deltaPosition)

float duration :动作执行持续时间,单位为秒。

const Vec2& deltaPosition:指定移动的距离。

[html] view plaincopyprint?auto sprite = Sprite::create("sprite.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 &#; origin.x, visibleSize.height/2 &#; origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); //创建MoveTo动作对象 auto moveto = MoveTo::create(0.9f,Point(,)); //创建Moveby动作对象 auto moveby = MoveBy::create(0.9f,Point(,)); //精灵执行动作 //sprite->runAction(moveto); sprite->runAction(moveby); 2. ScaleTo 和ScaleBy

scaleTo:不管精灵当前的拉伸倍数是多少,它都会把精灵缩放到指定的倍数。

ScaleTo::create(float duration, float sx, float sy)

float duration:动作的持续时间,单位为秒

float sx :X方向的拉伸&#;

float sy:Y方向的拉伸&#;

cocos2dx 3.x 动作的认识(cocos2d动画)

scaleBy:是在精灵当前的拉伸倍数的基础上,再次进行拉伸。例如精灵当前的拉伸倍数2.0,指定精灵x拉伸2.0f,y拉伸1.0f,则精灵的当前x拉伸倍数变为4.0f,就是在原来的2.0的基础上x再放大两倍。

ScaleBy::create(float duration, float sx, float sy)

float duration:动作的持续时间,单位为秒

float sx :X方向的拉伸&#;

float sy:Y方向的拉伸&#;

[html] view plaincopyprint?auto sprite = Sprite::create("sprite.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 &#; origin.x, visibleSize.height/2 &#; origin.y)); auto sprite2 = Sprite::create("sprite.png"); // position the sprite on the center of the screen sprite2->setPosition(Vec2(visibleSize.width/2 &#; , visibleSize.height/2 &#; origin.y)); sprite2->setScale(2.0f); auto sprite3 = Sprite::create("sprite.png"); // position the sprite on the center of the screen sprite3->setPosition(Vec2(visibleSize.width/2 - , visibleSize.height/2 &#; origin.y)); sprite3->setScale(2.0f); // add the sprite as a child to this layer this->addChild(sprite, 0); this->addChild(sprite2, 1); this->addChild(sprite3); //创建ScaleTo对象 auto scaleTo = ScaleTo::create(2.8f,1.0f,1.0f); //创建ScaleBy对象 auto scaleBy = ScaleBy::create(2.8f,2.0f,1.0f); //精灵执行动作 sprite3->runAction(scaleTo); sprite2->runAction(scaleBy); 3. Blink 精灵闪烁

Blink::create(float duration, int blinks)

float duration:动作持续时间,单位为秒

int blinks:闪烁次数

[html] view plaincopyprint?auto sprite4 = Sprite::create("sprite.png"); sprite4->setPosition(Vec2(visibleSize.width/2 - , visibleSize.height/2 &#; origin.y)); sprite4->setScale(2.0f); this->addChild(sprite4); //创建Blink动作对象 auto blink = Blink::create(3.0f,3); sprite4->runAction(blink); 4.BezierTo和BezierBy

创建贝塞尔曲线动作需要一个ccBezierConfig 对象,找个对象有3个属性:

bezier.controlPoint_1 :波谷偏向&#;bezier.controlPoint_2 :波峰偏小&#;bezier.endPosition :动作终点位置

BezierTo 直接移动到各个坐标点

BezierBy 是在精灵当前位置为基准进行移动的。

[html] view plaincopyprint?//创建贝塞尔曲线的配置 ccBezierConfig bezier; bezier.controlPoint_1 = Point(,0); bezier.controlPoint_2 = Point(,); bezier.endPosition = Point(,0); //创建BezierTo动作对象 auto bezierTo = BezierTo::create(3.0f,bezier); //创建BezierBy动作对象 //auto bezierBy = BezierBy::create(3.0f,bezier); sprite5->runAction(bezierTo); //sprite5->runAction(bezierBy); 5. repeatForever 和 repeat

repeatForever :创建一个永久性重复动作。

repeat:创建一个指定次数的动作。

[html] view plaincopyprint?auto sprite6 = Sprite::create("sprite.png"); sprite6->setPosition(Vec2(visibleSize.width/2 - , visibleSize.height/2 &#;)); this->addChild(sprite6); auto jumpBy = JumpBy::create(3.0f,Point(,1),,1); //以jumpBy为参数,创建个永久性的重复动作 auto repeatForever = RepeatForever::create(jumpBy); //以jumpBy为参数,创建个指定次数的重复动作 auto repeat = Repeat::create(jumpBy,3); //sprite6->runAction(repeatForever); sprite6->runAction(repeat); 6. Sequence和Spawn

Spawn:让所有的动作一起播放

Sequence:让动作一个一个播放

[html] view plaincopyprint?auto sprite = Sprite::create("sprite.png"); sprite->setPosition(Vec2(visibleSize.width/2 &#; origin.x, visibleSize.height/2 &#; origin.y)); this->addChild(sprite, 0); //创建一个移动动作对象 auto moveBy = MoveBy::create(2.2f,Point(,)); //创建一个弹跳动作 auto jumpBy = JumpBy::create(3.0f,Point(,1),,5); //创建一个旋转动作 auto rotateBy = RotateBy::create(2.5f,,); auto actions = Sequence::create(moveBy,jumpBy,rotateBy,NULL); //auto actions = Spawn::create(moveBy,jumpBy,rotateBy,NULL); //循环播放 //auto repeat = RepeatForever::create(actions); sprite->runAction(actions); 7. 动作监听

CallFunc 它的动作就是回调一个函数。使用CC_CALLBACK_0创建要回调的函数。

[html] view plaincopyprint?bool ActionTest::init() { // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto sprite = Sprite::create("sprite.png"); sprite->setPosition(Vec2(visibleSize.width/2 &#; origin.x, visibleSize.height/2 &#; origin.y)); this->addChild(sprite, 0); //创建一个移动动作对象 auto moveBy = MoveBy::create(2.2f,Point(,)); //创建一个弹跳动作 auto jumpBy = JumpBy::create(3.0f,Point(,1),,5); //创建一个旋转动作 auto rotateBy = RotateBy::create(2.5f,,); //auto actions = Sequence::create(moveBy,jumpBy,rotateBy,NULL); //auto actions = Spawn::create(moveBy,jumpBy,rotateBy,NULL); //循环播放 //auto repeat = RepeatForever::create(actions); auto moveto = MoveTo::create(.0f,Vec2(visibleSize.width, visibleSize.height/2 &#; origin.y)); auto callfunc = CallFunc::create(CC_CALLBACK_0(ActionTest::backhome,this)); auto actions = Sequence::create(moveto,callfunc,NULL); sprite->runAction(actions); return true; } void ActionTest::backhome() { auto lable = LabelTTF::create("I am Home!","Arial",); lable->setPosition(Point(,)); this->addChild(lable); }

Cocos2dx 3.3 遇到的问题 Xcode中提示:Useofundeclaredidentifier'...'一般是由于标识符未定义,或者相关头文件没有引入例如Useofundeclaredidentifier'CocosDenshion'需要添加头文件SimpleAudioEngine

Cocos2dx开发windows phone时,VS设置为横屏竖屏问题 1、首先打开自己的windowsphone的项目;2、把项目打开,可看到如下的结构:3、然后点击MainPage.xaml文件,可以看到如下结构:然后左边是显示的模拟器,

cocos2dx -- 学习笔记 利用UIButton制作虚拟按键 今天,继续完善自己的小DEMO,要加入一些虚拟按键,首先是,上下左右方向键。这里需要实现,按下持续走,松开则停止的效果。尝试着用CCMenuImage做

标签: cocos2d动画

本文链接地址:https://www.jiuchutong.com/biancheng/368883.html 转载请保留说明!

上一篇:cocos2dx 3.x 移植android(cocos2d安装)

下一篇:Cocos2dx 3.3 遇到的问题(cocos2dx 4.0)

  • 房地产销售商品房税率
  • 广东税务是什么
  • 公司账户钱能全部转走吗
  • 增值税少企业所得税多说明什么
  • 委托外单位研发的研发费用加计扣除最新政策
  • 餐饮注册个体工商户还是注册公司
  • 税控盘当月不抵扣怎么申报
  • 红字发票认证
  • 长期借款利息计入应付利息吗
  • 税务局代增值税专用发票冲红,如何重新申报退税
  • 先进技术企业的企业所得税税率
  • 租车费属于办公费吗
  • 托收承付和委托收款的含义和相同之处
  • 转让土地使用权怎么交增值税
  • 查定征收方式适用于什么
  • 企业报税盘入账应该记入哪个科目?
  • 报废 库存商品
  • 免税和应税无法划分
  • 忘记申报印花税,但是公司已经注销了怎么办
  • 非雇佣劳务
  • 政府收购企业资产规定
  • 个体户需要记账嘛
  • 小规模可以接收专票吗现在
  • 管理费用企业所得税标准
  • 三种测试网速的方法
  • 存出保证金的核算内容
  • 国家减免税款怎么申请
  • 存货跌价准备是什么意思
  • 企业记账的主要内容包括
  • 不确认收入要结转成本吗
  • 管理费用怎么记凭证
  • 商业汇票转让后,能否追索前手
  • 费用报销单怎么划线
  • 加计抵减和加计扣除是一样的吗
  • 工商变更后税务会自动变更吗
  • win11永久关闭桌面弹出广告
  • php 微信公众号自定义菜单
  • 研发专利什么意思
  • 2022年我们国家将举行什么样的盛会
  • 销售费用和管理费用占比多少合理
  • 小微企业所得税税率
  • 钢贸企业税收怎么算
  • 陈列费怎么开票
  • 收到费用报销单据应该怎么记账?
  • mysql Non-Transactional Database Only(只支持MyISAM)
  • 租赁厂房对方不租怎么办
  • 工程项目成本核算
  • 收到三代手续费的增值税报表填列在哪里
  • 应付账款长时间不付款怎么处理
  • 应收账款增加给哪一方
  • 主营业务利润率反映了企业的什么能力
  • 工程维修款扣多少
  • 资产减值损失属于损益类的收入还是费用
  • 佣金支付给谁
  • 哪些费用是不可抵扣的
  • 债务重组的方式主要包括哪些
  • mysql mod
  • mysql的外键
  • mysql 5.7.28安装
  • 快速调用cmd
  • 怎样让windows media player播放mkv文件
  • 七喜r11c笔记本
  • linux使用su命令出错
  • win7 分区表
  • 苹果预计10.1-15号到能准确吗
  • linux系统添加新用户
  • Msssrv.exe - Msssrv是什么进程 有什么用
  • 文件夹底部显示
  • linux统计文件中每个单词出现的次数
  • linux如何使用命令创建文件夹
  • 日历控件默认日期
  • 如何使用jquery绑定事件
  • html通配符选择器怎么用
  • javascript高级程序设计pdf百度云
  • jQuery中checkbox反复调用attr('checked', true/false)只有第一次生效的解决方法
  • 面试java基础知识
  • 哈尔滨工业大学录取分数线2023年
  • 期初未缴税额是什么意思
  • 福建电子税务局登录入口
  • 税控盘如何查询季度统计
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设