如何在 AS3 中访问 Flash 中的不同影片剪辑

发布于 2024-08-29 13:14:27 字数 330 浏览 9 评论 0原文

过去几周我一直在尝试学习 Action Script 3,制作一些小型互动游戏来学习基础知识。我时不时地会遇到一个问题,但大多数时候谷歌都会帮助我解决。

但这个问题让我陷入困境,所以请帮忙:

主舞台包含两个对象(电影剪辑),播放器和一面墙。 玩家有自己的代码,因此当我拖入玩家对象时,我不必在主舞台中编写任何代码即可移动玩家。

这一切都运行得很好,我现在想添加墙,这样玩家实际上就有了可以弹跳的东西。

现在问题来了,我想检查玩家是否接触到墙壁,我之前已经这样做过,但那是当我使用主舞台作为我的编码游乐场而不是将代码放入影片剪辑中时。如何在玩家对象的移动代码中检查玩家是否撞到了墙壁?

I've been trying to learn Action Script 3 the past few weeks, making tiny interactive games to learn the basics. I stumble upon a problem every now and then but most of the times google helps me out.

But this problem has got me stuck so please help:

The main stage contains two objects(movieclips), the player and a wall.
The player has got his own code so when I drag in the player object I don't have to write any code into the main stage to be able to move the player.

This all worked pretty well and I now wanted to add the wall so the player actually has something to bounce into.

Now here is the problem, I want to check if the player touches the wall, I've done this before but that was when I used the main stage as my coding playground instead of putting the code in movieclips. How can I check if the player hits the wall within the movement code of the player object?

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

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

发布评论

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

评论(1

轻许诺言 2024-09-05 13:14:27

有很多方法可以访问您的对象,这是一种可能的解决方案:

var wall:MovieClip = this.parent.getChildByName("wall") as MovieClip;

我假设您有一个播放器 movieClip,直接添加到舞台(无容器),并且代码位于该对象内部。 Wall 对象的实例名称必须为“wall”。

编辑:关于碰撞,您可以使用 hitTestObject 来完成,例如:

var wall:MovieClip = this.parent.getChildByName("wall") as MovieClip;
trace("check collision: "+this.hitTestObject(wall));

There are many ways to access your objects, here is one possible solution:

var wall:MovieClip = this.parent.getChildByName("wall") as MovieClip;

I presume that you have a player movieClip, added to stage directly (no containers) and the code goes inside this object. Wall object must have the instance name of "wall".

EDIT: about the collision you can do it using hitTestObject, example:

var wall:MovieClip = this.parent.getChildByName("wall") as MovieClip;
trace("check collision: "+this.hitTestObject(wall));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文