Javascript 平稳运动

Javascript 平稳运动,javascript,html,phaser-framework,Javascript,Html,Phaser Framework,我想在点击按钮时移动:左。 这是移动的运动 问题在于它的行动,但只有一次。我需要点击垃圾邮件按钮 代码: 在创建中: this.buttonleft.inputEnabled = true; this.buttonleft.events.onInputDown.add(this.clickMoveLeft, this); this.buttonleft.mouseDownCallback = false; this.buttonleft.alpha = false; // Making no

我想在点击按钮时移动:左。 这是移动的运动

问题在于它的行动,但只有一次。我需要点击垃圾邮件按钮

代码:

在创建中:

this.buttonleft.inputEnabled = true;
this.buttonleft.events.onInputDown.add(this.clickMoveLeft, this);
this.buttonleft.mouseDownCallback = false;

this.buttonleft.alpha = false; // Making no visable
在“一切-单独功能”下:

clickMoveLeft: function()
{
    if(!this.clickMoveLeft.mouseDownCallback)
    {
        this.player.body.velocity.x = -160;
        this.buttonleft.mouseDownCallback = true;

    }
    else if (!this.clickMoveLeft.mouseUpCallback) 
    {
        this.player.body.velocity.x = 0;
        this.buttonleft.mouseDownCallback = false;
}

我不知道phaser框架,但是,知道js事件是如何工作的,并且在一次调用之后,我非常确定当您单击鼠标时,.mouseDownCallback回调只会触发一次,而不是continuos。
因此,您可以使用mousedown事件来调用一个函数,该函数将继续移动您要移动的内容,并使用mouseup停止移动。

您的意思是,当您单击按钮时,“形状”将向左移动,然后向右移动。然后再跳一遍,重复一遍?但它什么时候会停止?当我点击左键时,精灵移动了一次。(160)我需要多次单击才能移动。我想得到这样的结果;我点击并按住按钮,精灵移动直到我不按住按钮