AS3 AI hitTestObject 与自身?
我创建了一个每 1 秒启动一次的计时器。 这是每 1 秒发生的代码。
var Random_Value_X:Number = Math.ceil(Math.random() * 1500);
var Random_Value_Y:Number = Math.ceil(Math.random() * 2000);
var enemy:MovieClip = new AI(stage);
addChild(hero);
enemy.x = Random_Value_X;
enemy.y = Random_Value_Y;
好的。然后我创建了一个名为 AI 的类,以便 AI 跟随我的玩家。问题是,我需要做一个 hitTest 来测试一个 AI 是否击中另一个 AI?有没有办法给每个新的人工智能一个ID?就像第一个被称为“AI1”和第二个 AI2“一样,然后我可以编写一个类似 If(AT1.hitTestObject(AT2 || AT3)) 的代码
希望你明白我试图解释的内容!:)
Im've created a timer that starts every 1 second.
This is the code what's happening every 1 second.
var Random_Value_X:Number = Math.ceil(Math.random() * 1500);
var Random_Value_Y:Number = Math.ceil(Math.random() * 2000);
var enemy:MovieClip = new AI(stage);
addChild(hero);
enemy.x = Random_Value_X;
enemy.y = Random_Value_Y;
Ok. Then I got the class called AI where I've made it so the AI follows my player. The thing is, I need to make a hitTest that testes if an AI hitting another AI? Is there a way I can give every new AI a ID? Like the first gets called "AI1" and second AI2" and then I can make a code that says like If(AT1.hitTestObject(AT2 || AT3))
Hope you understand what I trying to explain! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该把它们全部放在一个数组中。然后您可以循环遍历数组并对每个数组进行命中测试。根据您拥有的数量,您可能需要将它们分成几组,这样您就不必在每帧上进行如此多的检查。
我很确定你不能只在 hitTestObject 方法中使用逻辑或。
You should just put them all in an array. Then you can loop through the array and do the hit testing for each one. Depending on how many you have, you might need to split them up into groups so you don't have to do so many checks each frame.
I'm pretty sure you can't just use logical or in the hitTestObject method like that.
考虑到您位于根目录上,并且关键字“this”指的是根目录。如果您创建“enemy”类的实例,那么它的所有对象都将具有“enemy”类型。
Considering that you are on root and keyword "this" referring root. If you make instance of class "enemy" then all objects of it will have type "enemy".