一个物体一直左右运动,速度为600像素每秒,每点击三次就加速20像素.
原本是点击三次,停止所有动作改了速度之后再重新添加动作,但是如下面的代码,每次加速后必定会突然向右,无论刚才是在向左运动还是向右运动,所以大概是行不通的,目前打算直接修改动作的速度,但是不知道怎么修改.autoMove: function(speed){
var deltaTime = 700/speed;
this.moveToPosL = cc.p(-350, -18);//移动最左端
this.moveToPosR = cc.p(350, -18);//移动最右端
var moveToR = cc.moveTo(deltaTime,this.moveToPosR);
var moveToL = cc.moveTo(deltaTime,this.moveToPosL);
var moveSeq = cc.sequence(moveToR, moveToL);
moveToR.setTag(1);
moveToL.setTag(2);
moveSeq.setTag(3);
var move = cc.repeatForever(
moveSeq//移动队列
);
console.log("delta: "+deltaTime);
move.setTag(4);
this.node.runAction(move);
},
onLoad: function () {
this.autoMove(this.speed);
console.log(this.node.getActionByTag(4));
},
update (dt) {
if(parseInt(this.count/3) > this.speedBeilv){
//this.speedBeilv = parseInt(this.count/3);
//this.speed += 20;
//this.node.stopAllActions();
//this.autoMove(this.speed);
this.node.getActionByTag(4)._speed += 2;
console.log(this.node.getActionByTag(4)._speed);
console.log(this.node.getActionByTag(4));
// console.log("count2:"+parseInt(this.count/3));
// console.log("speedBeilv: "+this.speedBeilv);
// console.log("speed: "+this.speed);
}
//console.log(this.count);
},
想通过查找tag的方式得到向左和向右两个动作,然后直接改变speed,但是通过tag只能获取到move这个动作,另外三个不知道怎么查找.
想问一下有没有什么其它思路完成这个功能,或者能查找到队列里的两个动作?