我的方法是这样的,用两张图片修改 y 的值来滚动。
就像上面的图,road1 road2 road3是三张交替滚动的图。
下面是滚动代码
update(dt){
//speed 滚动速度
this.speed = this.node.parent.getComponent("roadManager").speed;
if (this.node.y<= this.minY){ //如果到达最底部,将图片设置到起始位置。
this.node.y= this.resety;
}
this.node.y -= this.speed * dt;//改变road的y坐标
},
我通过修改speed 的值来改变滚动速度。speed的初始值是0;点击加速按钮后,
speed 的值 慢慢增加到最大速度 。代码是这样式儿的。
update (dt) {
//gear 档位 D档行驶 N档减速滑行 B档刹车
if (this.gear == Gear.D)
this.speed += this.acceleration;//加速 acceleration 加速值,每帧 为speed加10
if (this.speed > this.maxSpeed) //最大速度
this.speed = this.maxSpeed;
if (this.gear == Gear.N)
this.speed -= this.decelerate;//减速 滑行时减速值 每帧为speed减5
if (this.gear == Gear.B)
this.speed -= this.carbrake;//刹车时的减速 每帧为 speed减20
if (this.speed <0)
this.speed = 0;
},
我这样做,在浏览器里运行很流畅。但是构建到andriod里,在加速的过程中
就一卡一卡的。达到最大速度后才流畅的滚动。
我搞不懂是什么原因。求大神们赐教啊。