
本文测试所用Cocos2d-HTML5版本:2.2.1。
Moveto:移动到某个位置,是绝对距离。
MoveBy:移动一段距离,是相对距离。
使用cc.Moveto.create(duration,deltaposition)和cc.MoveBy.create(duration,deltaposition)来创建动作。
duration 运动周期,单位为s。 deltaposition 坐标点,使用cc.p(x,y)或者new cc.Point(x,y)请看下列代码:
var GameScene = cc.Scene.extend({ enemy1: null,// 敌人1 enemy2: null,// 敌人2 enemy3:null,// 敌人3 layer: null,// 布景 winSize: null,// 游戏运行窗口尺寸 onEnter: function () { this._super(); this.initData(); }, initData: function () { // 获取尺寸 this.winSize = cc.Director.getInstance().getWinSize(); // 添加布景 this.layer = cc.Layercolor.create(cc.c4(200,200,255),this.winSize.wIDth,this.winSize.height); this.addChild(this.layer); // 创建动作 var actionTo = cc.Moveto.create(2,cc.p(this.winSize.wIDth - 40,this.winSize.height - 40)); var actionBy = cc.MoveBy.create(2,cc.p(40,40)); var actionByBack = actionBy.reverse(); // 添加敌人1 this.enemy1 = cc.Sprite.create(s_enemy_1); this.layer.addChild(this.enemy1); this.enemy1.runAction(actionTo); // 添加敌人2 this.enemy2 = cc.Sprite.create(s_enemy_2); this.enemy2.setposition(cc.p(40,40)); this.layer.addChild(this.enemy2); this.enemy2.runAction(cc.Sequence.create(actionBy,actionByBack)); // 添加敌人3 this.enemy3 = cc.Sprite.create(s_enemy_3); this.enemy3.setposition(cc.p(80,80)); this.layer.addChild(this.enemy3); this.enemy3.runAction(cc.MoveBy.create(2,cc.p(100,0))); } });以下是运行结果截图:
总结以上是内存溢出为你收集整理的Cocos2d-html5之MoveTo&MoveBy全部内容,希望文章能够帮你解决Cocos2d-html5之MoveTo&MoveBy所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)