AS3 How to startdrag only on x-axis?

前端 未结 3 1751
攒了一身酷
攒了一身酷 2020-12-19 10:33

I have a red square that I want to drag only on the x-axis. I\'ve worked out a simple script, which theoretically should work, but it\'s not behaving properly. It\'s a bit h

3条回答
  •  忘掉有多难
    2020-12-19 11:01

    THIS WILL WORK ACTIONSCRIPT 3 (Semilla Sol Apps)

    1- create your regular MOUSE DOWN and MOUSE UP event listeners

    2- drop your 'startDrag' and 'stopDrag' elements in each function thereof respectively

    HERE IS HOW TO LOCK DOWN THE AXIS:

    1: create an event listener for the object you wish to restrict...in this example it's a movieclip instance named 'player':

    player.addEventListener(Event.ENTER_FRAME, pLimiter);
    

    HERE IS THE 'pLimter' FUNCTION:

    function pLimiter(e:Event):void
    {
        player.y = stage.stageHeight;
    }
    

    So in this case we are restricting 'drag' to only the x axis.

    • party on dude! (Semilla Sol Apps)

提交回复
热议问题