如何引用单个类的多个实例?

发布于 2024-12-28 22:28:37 字数 197 浏览 2 评论 0原文

所以我知道如何使用 MovieClip(root).objectName 来定位特定实例,我认为无论如何引用它都是令人讨厌的方式,但现在我正在尝试制作一个格斗简笔画游戏,我只能引用我的代码现在使用“敌人”类对一个 NPC 进行攻击,但如果我可以使用敌人类一次生成多个 NPC,并以敌人类而不是实例本身为目标,同时仍使 NPC 实例保持唯一,那么我希望这样打他们一个不要全部被击中。

So I know how to target a specific instance using MovieClip(root).objectName which I think is nasty way of referring to it anyways, but right now I'm trying to make a fighting stick-figure game and I can only refer my code to one NPC right now using an "enemy" class but I would like it if I could spawn multiple NPC's at once using the enemy class and instead target the enemy class instead of the instance itself while still having the NPC instances being unique so when I hit one they don't all get hit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沒落の蓅哖 2025-01-04 22:28:37

为你的敌人类别创建一个数组,如下所示:

NPCArray = [];

for ( var i = 0; i < 10; i++)
{
   var npc:NPC = new NPC();
   NPCArray.push(npc);
   this.addChild(npc);
}

那么当您想要更新它们时:

for ( var i = 0; i < NPCArray.length; i++)
{
   var npc:NPC = NPCArray[i];
   npc.update()
}

我建议您阅读本教程,它解释了 AS3 游戏开发的基础。 http://gamedev.michaeljameswilliams.com/2008/09/ 17/avoider-game-tutorial-1/

create an array for your enemy class, like this:

NPCArray = [];

for ( var i = 0; i < 10; i++)
{
   var npc:NPC = new NPC();
   NPCArray.push(npc);
   this.addChild(npc);
}

then when you want to update them all:

for ( var i = 0; i < NPCArray.length; i++)
{
   var npc:NPC = NPCArray[i];
   npc.update()
}

I would recommend reading this tutorial, that explains the basis of AS3 game development. http://gamedev.michaeljameswilliams.com/2008/09/17/avoider-game-tutorial-1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文