我想为移动的物体添加一些轨迹效果,随着时间的推移会逐渐消失。这是我到目前为止所得到的:
game.Trail = me.Entity.extend({
init:function (x, y, settings)
{
this._super(me.Entity, 'init', [
x, y,
{
image: "ball",
width: 32,
height: 32
}
]);
(new me.Tween(this.renderable))
.to({
alpha : 0,
}, 5000)
.onComplete((function () {
me.game.world.removeChild(this);
}).bind(this))
.start();
},
update : function (dt) {
this.body.update(dt);
return (this._super(me.Entity, 'update', [dt]) || this.body.vel.x !== 0 || this.body.vel.y !== 0);
}
});
演示(使用 WASD 或箭头键移动)
这是完整项目的链接,可在本地进行测试。
但我想以与褪色相同的方式更改轨迹中项目的颜色。
在移相器中,这可以为精灵着色,但我不知道如何在 melonjs 上实现这一点。
注意:如果效果可以用基本形状而不是图像来完成,那也可以。