触发双击功能,并按住最后一次单击AS3

时间:2015-03-19 20:50:17

标签: actionscript-3 flash mouse double-click

我有一个游戏,我的角色向右或向左移动,使用MOUSE_DOWN eventlistener。角色跳转,使用DOUBLE_CLICK eventlistener。 我想要它,以便如果玩家双击并按住最后一次点击,那么角色会跳跃并移动。 就像现在一样,只有当玩家双击并释放鼠标时,跳跃功能才有效。 这有可能吗?

所以只是为了让它更清晰一些。当玩家双击并释放时,角色将跳到他站立的位置。这已经有效了。 但如果玩家双击并按住,则应触发跳转功能和移动功能。

提前致谢!

包{

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;


public class Main extends MovieClip {

    public var character:Character = new Character;
    public var world:World = new World;

    var moveRight:Boolean = false;
    var moveLeft:Boolean = false;
    var jumping:Boolean = false;

    var moveSpeed:Number = 1;
    var orgMoveSpeed:Number = 1;
    var accSpeed:Number = 0.6;
    var maxMoveSpeed:Number = 20;
    var gravity:Number = 1;
    var orgGrav:Number = 1;
    var gravAcc:Number = 0.6
    var maxFallSpeed:Number = 15;
    var jumpPower:Number = 15;
    var jumpGrav:Number = 0.6;
    var orgJumpPower:Number =15;
    public function Main() {
        // constructor code
        addChild(world)
        addChild(character)

        stage.doubleClickEnabled=true;
        stage.addEventListener(MouseEvent.MOUSE_DOWN, moveFunction)
        stage.addEventListener(MouseEvent.MOUSE_UP, stopMoveFunction)
        stage.addEventListener(MouseEvent.DOUBLE_CLICK, jumpFunction)
        addEventListener(Event.ENTER_FRAME, moveWorld)
    }
    function moveFunction(m:MouseEvent)
    {
    //If the player clicks on right side of the screen, the player moves right.. etc.
        if(mouseX>stage.stageWidth/2)
        {
            moveRight = true
        }else{
            moveLeft = true
        }
    }
    function stopMoveFunction(m:MouseEvent)
    {
        moveLeft = false;
        moveRight = false;
    }

    function jumpFunction(m:MouseEvent)
    {
        if(hitGroundCol)
        {
            jumping=true;
        }
    }

    function moveWorld(e:Event)
    {

//_______MOVE FUNCTION _____________________
        if (moveRight)
        {
            world.x -= moveSpeed
            moveSpeed += accSpeed
            character.OddSlugViz.rotation += moveSpeed
        }else if (moveLeft)
        {
            world.x += moveSpeed
            moveSpeed += accSpeed
            character.OddSlugViz.rotation -= moveSpeed
        }else{
            moveSpeed = orgMoveSpeed;
        }

        if (moveSpeed>maxMoveSpeed)
        {
            moveSpeed = maxMoveSpeed;
        }
//_________Jump_________________

        if (jumping)
        {
            world.y += jumpPower
            jumpPower -= jumpGrav
            if (jumpPower<1)
            {
                jumping = false;
                jumpPower = orgJumpPower;
            }
        }
    }
}

}

1 个答案:

答案 0 :(得分:1)

一个简单的解决方案是跟踪单击甚至启动计时器或超时,如果在一个时间限制内发生另一个鼠标按下事件(100毫秒?你必须测试看看你想要多么自然) ,然后做事件..这样你可以跟踪鼠标被按住,并且它是双击,而不使用双击事件。