位置: 编程技术 - 正文

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)

  • 分公司可以享受企业所得税优惠吗
  • 纳税义务发生时间记忆口诀
  • 劳务公司一般纳税人可以抵扣进项税吗
  • 一般纳税人和小规模纳税人哪个合适
  • 劳务发票要交多少税费
  • 中税税务咨询
  • 哪些情况需要提高警惕小心毒品
  • 如何开银行卡账户
  • 发票税率开错了3%开成5%怎么办
  • 代加工可靠吗
  • 税屋网官网房屋
  • 现代服务业加计抵减政策适用范围
  • 企业怎么挑选计提折旧方式方法
  • 外购礼品发放员工
  • 应收分保合同准备材料
  • 财务费用手续费有哪些
  • 处置子公司的收益
  • 房屋出售缴纳税种
  • 财税政策是什么
  • 现金采购合理吗
  • 一般公司报销一个月报销几次
  • 交易性金融资产和长期股权投资的区别
  • 加速折旧法主要包括哪些内容
  • 人均营收指标
  • 房产税发票可以抵扣吗
  • 增值税认证平台确认以后还可以再认证吗
  • 坏账准备年末余额怎么计算
  • 支付委托加工费用会计科目
  • 长期待摊费用是当月摊销还是次月摊销
  • 营改增建筑业税率是多少
  • php初学实例教程
  • 合同已无法履行
  • php获取ftp文件目录
  • 纳税人逾期申报
  • 在建工程减值准备科目编码
  • 博茨瓦纳热吗
  • uniapp按钮
  • 浅谈php的数据库管理系统
  • 班迪录屏软件录制框怎样在ppt上一直指定
  • deepsort 跟踪
  • thinkphp环境搭建教程
  • 增值税进项和销项怎么抵扣
  • 个体户个税征收标准
  • 金税盘服务费可以跨年抵扣
  • Mysql创建通用设备管理信息系统数据库
  • 小规模纳税人的条件
  • 企业应纳税所得额的计算原则
  • 本月收入未开票会计分录
  • 免费赠送客户入群的文案
  • 公司为员工购买小汽车属于什么所得
  • 开红字发票做账时记账凭证上如何写摘要?
  • 营改增后建筑业开票规定
  • 公司认缴没有实缴会有什么风险
  • 个人支付宝开票一年可以开多少
  • 租房开的发票收的税如何做账?
  • 客户将发票丢了怎么赔偿
  • 成本收入率和收入成本率的区别
  • 利润表季度表怎么填
  • 收款凭证和付款凭证是出纳人员收款、付款的依据
  • sql有哪些语句
  • w10语言栏
  • centos6.5mini安装教程
  • xp系统如何删除用户
  • ubuntu20.04亮度调节
  • ati2sgag.exe进程安全吗 ati2sgag进程信息查询
  • ubuntu装eclipse
  • win8怎么禁止弹窗
  • windows进程太多
  • nodejs 用途
  • nodejs读取文件和写文件的方法
  • 静态文件格式有哪些
  • 三消游戏在线
  • iframe和frame
  • python函数参数的传递方法
  • 详解Python中的Descriptor描述符类
  • 吉林省残疾人保障金减免政策
  • 电梯维护保养费按什么缴纳增值税
  • 企业破产享有的债权可否提前到期
  • 内蒙古物业费收取标准2020
  • 统一社会信用代码有什么用
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设