如何在 AS3 中访问 Flash 中的不同影片剪辑
过去几周我一直在尝试学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以访问您的对象,这是一种可能的解决方案:
我假设您有一个播放器 movieClip,直接添加到舞台(无容器),并且代码位于该对象内部。 Wall 对象的实例名称必须为“wall”。
编辑:关于碰撞,您可以使用 hitTestObject 来完成,例如:
There are many ways to access your objects, here is one possible solution:
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: