Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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 如何在as3 flash中检测碰撞和堆叠坠落物体?_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 如何在as3 flash中检测碰撞和堆叠坠落物体?

Actionscript 3 如何在as3 flash中检测碰撞和堆叠坠落物体?,actionscript-3,flash,Actionscript 3,Flash,当我试图让sqares堆叠时,我遇到了一个小问题,就像俄罗斯方块一样。 我不知道如何控制不同的方块,以便检查碰撞。我已经做了一个正方形与as3链接名称广场 var timer:Timer = new Timer(12); timer.addEventListener(TimerEvent.TIMER, doStuff); timer.start(); var newSquare= new Square(); nyFirkant.y = 0;

当我试图让sqares堆叠时,我遇到了一个小问题,就像俄罗斯方块一样。 我不知道如何控制不同的方块,以便检查碰撞。我已经做了一个正方形与as3链接名称广场

    var timer:Timer = new Timer(12);

    timer.addEventListener(TimerEvent.TIMER, doStuff);

    timer.start();

    var newSquare= new Square();
    nyFirkant.y = 0;
    nyFirkant.x = Math.floor( Math.random() * 4) * 100;
    addChild(newSquare);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, tastLytter);

    function keyListener(evt:KeyboardEvent)
    {
    var key:int = evt.keyCode;

    if (key== Keyboard.RIGHT && newSquare.x < 400)
      {
        newSquare.x +=  100;
    }
   if (key== Keyboard.LEFT && newSquare.x > 0)
    {
        newSquare.x -=  100;
    }

    }


    function doStuff(evt:TimerEvent)
    {
    if (newSquare.y <= 400 - newSquare.height)
    {
        newSquare.y = newSquare.y + 2;
    }
    if (newSquare.y == 350)
    {
        newSquare= new Square();
        newSquare.y = 0;
        newSquare.x = Math.floor( Math.random() * 4) * 100;;

        addChild(newSquare);

    }



    }
var定时器:定时器=新定时器(12);
timer.addEventListener(TimerEvent.timer,doStuff);
timer.start();
var newSquare=newSquare();
y=0;
nyFirkant.x=数学地板(数学随机()*4)*100;
addChild(新闻广场);
stage.addEventListener(KeyboardEvent.KEY_DOWN,tastlyter);
函数keyListener(evt:KeyboardEvent)
{
var key:int=evt.keyCode;
if(key==Keyboard.RIGHT&&newSquare.x<400)
{
newSquare.x+=100;
}
if(key==Keyboard.LEFT&&newSquare.x>0)
{
newSquare.x-=100;
}
}
函数doStuff(evt:TimerEvent)
{

如果(newSquare.y使用hitTestObject,则它是MovieClip类中的一个方法

if (firstBlock.hitTestObject(secondBlock)) {
    trace("This block hit the other block");
    //Do stuff
}
很明显,这不是一个“临时”解决方案-您最好使用物理引擎,例如,但hitTestObject应该可以满足您的需要