简体   繁体   English

HitTestObject 两个 MovieClip Actionscript 3.0

[英]HitTestObject Both MovieClip Actionscript 3.0

I want to make a player and 2 Circles.我想制作一个播放器和 2 个圆圈。

When the player hit the first Circle, then the Circle will also move as like player.当玩家击中第一个圆圈时,圆圈也会像玩家一样移动。 Continue with the second Circle, if the second circle get hit by the first circle (while the player is moving and pushing the first circle), the second circle will also move as like player's speed movement!继续第二个圆,如果第二个圆被第一个圆击中(当玩家移动并推动第一个圆时),第二个圆也会像玩家的速度移动一样移动!

Can you solve the problems, please ... :) Thank You!请问你能解决问题吗... :) 谢谢!

Use the addChild() method.使用addChild()方法。

var circle1Hit:Boolean = false;
var circle2Hit:Boolean = false;

function myHitTest(me:MouseEvent): void 
{
    if (player.hitTestObject(circle1) && circle1Hit == false){
        circle1Hit = true;
        var _x:Number = circle1.x - player.x;
        var _y:Number = circle1.y - player.y;
        player.addChild(circle1)
        circle1.x = _x;
        circle1.y = _y;
    }
    if (player.hitTestObject(circle2) && circle2Hit == false)
    {
        circle2Hit = true;
        var _x:Number = circle2.x - player.x;
        var _y:Number = circle2.y - player.y;
        player.addChild(circle2)
        circle2.x = _x;
        circle2.y = _y;
    }
}

For further reading check out this great tutorial that explains containers and OOP really well.如需进一步阅读,请查看这个很棒的教程,它非常好地解释了容器和 OOP。 Also check out the one on Arrays from the same author here .也可以在这里查看来自同一作者的关于 Arrays 的文章。 By using an array, you could add even more circles to the array and all of them would be able to stick like these two do without having to have a separate bit of code for each circle like we have here.通过使用数组,您可以向数组中添加更多的圆圈,并且所有圆圈都可以像这两个一样粘在一起,而不必像我们这里那样为每个圆圈编写单独的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM