Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何调整对象的拖动速度?_Actionscript 3_Flash_Air - Fatal编程技术网

Actionscript 3 如何调整对象的拖动速度?

Actionscript 3 如何调整对象的拖动速度?,actionscript-3,flash,air,Actionscript 3,Flash,Air,好的,我正在开发一个游戏,要求玩家拖动一个物体,然后把它放在罐子里。我发现更容易指定x坐标限制,以确定他们正在拖动的对象何时应该模拟放入罐子。到目前为止,我的代码工作得非常好。但是,当玩家将对象移动到超过x坐标限制的速度过快时,将忽略当对象跨越x坐标限制时启动的动作脚本。我想我可以通过限制物体的拖动速度来解决这个问题。有人对如何实现这一目标有什么指导吗 这是我的密码: jarFront.mouseEnabled = false; jarFront.mouseChildren = false;

好的,我正在开发一个游戏,要求玩家拖动一个物体,然后把它放在罐子里。我发现更容易指定x坐标限制,以确定他们正在拖动的对象何时应该模拟放入罐子。到目前为止,我的代码工作得非常好。但是,当玩家将对象移动到超过x坐标限制的速度过快时,将忽略当对象跨越x坐标限制时启动的动作脚本。我想我可以通过限制物体的拖动速度来解决这个问题。有人对如何实现这一目标有什么指导吗

这是我的密码:

jarFront.mouseEnabled = false; jarFront.mouseChildren = false;

// animate buttons in
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.Event;

var objArray:Array = new Array;

objArray.push(obj1);
objArray.push(obj2);
objArray.push(obj3);

var objPosition:Point;

function dragobj(e:Event):void {
e.currentTarget.startDrag();
objPosition = new Point( e.currentTarget.x, e.currentTarget.y);
}           
function dragobjStop(e:Event):void {
    e.currentTarget.stopDrag(); 
    e.currentTarget.x = e.currentTarget.x;
    e.currentTarget.y = objPosition.y;
    objPosition = null;
}


for (var i:uint = 0; i < objArray.length; i++) {
    objArray[i].addEventListener(MouseEvent.MOUSE_DOWN, dragobj);
    objArray[i].addEventListener(MouseEvent.MOUSE_UP, dragobjStop);
}

// Drop in jar



var HighH:int=400;
var HighW:int=400;
var LowH:int=-200; var LowW:int=0;
var HighyH:int=170;
var HighyW:int=170;
var LowyH:int=0; var LowyW:int=0;

this.addEventListener( Event.ENTER_FRAME, goJar)
function goJar( e:Event ):void
{
  if (obj1.x > 400 && obj1.x < 440) { 
        obj1.stopDrag();
           //set back or tween position 
           obj1.x = 83;
           obj1.y = -300;
           this.setChildIndex(obj1,1)
           var ct1_1:Tween = new Tween(obj1, "y", None.easeNone, obj1.y, obj1.y=Math.floor(Math.random()*(1+HighyH-LowyH))+LowyH, .2, true);
           var ct1_2:Tween = new Tween(obj1, "rotation", Bounce.easeOut, 0, 180, 1, true);
           var ct1_3:Tween = new Tween(obj1, "x", None.easeNone, obj1.x, obj1.x=Math.floor(Math.random()*(1+HighH-LowH))+LowH, .2, true);

    } else {


// keep inside jar

        if (obj1.x > -330 && obj1.x < -260) { 
        obj1.stopDrag();
           //set back or tween position 
           obj1.x = 83;
           obj1.y = -300;
           this.setChildIndex(obj1,1)
           var ct1_4:Tween = new Tween(obj1, "y", None.easeNone, obj1.y, obj1.y=Math.floor(Math.random()*(1+HighyH-LowyH))+LowyH, .2, true);
           var ct1_5:Tween = new Tween(obj1, "rotation", Bounce.easeOut, 0, 180, 1, true);
           var ct1_6:Tween = new Tween(obj1, "x", None.easeNone, obj1.x, obj1.x=Math.floor(Math.random()*(1+HighH-LowH))+LowH, .2, true);

    }
}

}
jarFront.mouseEnabled=false;jarFront.mouseChildren=false;
//在中设置按钮动画
导入fl.transitions.Tween;
导入fl.transitions.easing.*;
导入fl.transitions.TweenEvent;
导入flash.events.Event;
var objArray:Array=新数组;
objArray.push(obj1);
objArray.push(obj2);
推送(obj3);
变量对象位置:点;
函数dragobj(e:事件):void{
e、 currentTarget.startDrag();
objPosition=新点(e.currentTarget.x,e.currentTarget.y);
}           
函数dragobjStop(e:事件):void{
e、 currentTarget.stopDrag();
e、 currentTarget.x=e.currentTarget.x;
e、 currentTarget.y=对象位置.y;
objPosition=null;
}
for(变量i:uint=0;i400&&obj1.x<440){
obj1.stopDrag();
//后退或中间位置
obj1.x=83;
obj1.y=-300;
此.setChildIndex(obj1,1)
变量ct1_1:Tween=新Tween(obj1,“y”,None.easeNone,obj1.y,obj1.y=数学地板(Math.random()*(1+HighyH-LowyH))+LowyH.2,真);
变量ct1_2:Tween=新Tween(obj1,“旋转”,Bounce.easeOut,0,180,1,true);
变量ct1_3:Tween=新Tween(obj1,“x”,None.easeNone,obj1.x,obj1.x=数学地板(数学随机()*(1+HighH-LowH))+LowH.2,真);
}否则{
//放在罐子里
如果(obj1.x>-330&&obj1.x<-260){
obj1.stopDrag();
//后退或中间位置
obj1.x=83;
obj1.y=-300;
此.setChildIndex(obj1,1)
变量ct1_4:Tween=新Tween(obj1,“y”,None.easeNone,obj1.y,obj1.y=数学地板(Math.random()*(1+HighyH-LowyH))+LowyH.2,真);
变量ct1_5:Tween=新Tween(obj1,“旋转”,Bounce.easeOut,0,180,1,true);
变量ct1_6:Tween=新Tween(obj1,“x”,None.easeNone,obj1.x,obj1.x=数学地板(Math.random()*(1+HighH-LowH))+LowH.2,真);
}
}
}

此外,如果有一种方法可以在上面的数组函数中包含“//Drop-in-jar”下面的所有内容,这样该操作脚本就可以自动应用于obj2和obj3,这将非常有帮助。

这里没有限制拖动对象移动的代码。如果要限制对象位置,只需将矩形对象传递给startDrag方法。

谢谢BotMaster,根据您的指示,我修改了代码如下:

var rectangle1:Rectangle = new Rectangle(400, -665, 1156, 1052);
var rectangle2:Rectangle = new Rectangle(-376, -665, 721, 1052);
var candyPosition:Point;


function dragCandy(e:Event):void {
    if (e.currentTarget.x > 400) {
        e.currentTarget.startDrag(false, rectangle1);
        candyPosition = new Point( e.currentTarget.x, e.currentTarget.y);
        } else {
            e.currentTarget.startDrag(false, rectangle2);
            candyPosition = new Point( e.currentTarget.x, e.currentTarget.y);
            }
        }
基本上,这里发生了什么:

  • 如果对象位于大于400的x位置,则拖动将被约束为矩形1
  • 一旦对象被拖动到罐子外部的特定x位置,它就会在罐子内部变粗
  • 既然对象在jar中,它的新x位置将小于400,拖动将被约束到矩形2
  • 现在,当对象被拖到jar的上方,在hitTestObject的顶部时,它将被拖回jar外侧的一个随机位置

  • 感谢BotMaster,根据您的指示,我找到了一种方法,可以在舞台上创建两个不同的矩形,并根据对象的x位置确定要限制对象位置的矩形