AS3 确定什么对象重叠它?
我目前正在用 as3 构建一个游戏;我现在遇到的问题是,当我掷虚拟骰子时,玩家(标记)在棋盘上移动,但我需要知道的是:有没有办法找到玩家着陆的对象(盒子)的实例名称在?
抱歉我的英语不好。
I'm current building a game in as3; the proplem I have right now is when I roll the virtual dice, the player(marker) moves accross the board but what I need to know is: is there a way to find the instance name of the object(box) that the player lands on?
And Sorry my english isn't good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在很大程度上取决于您的电路板的布局方式。一种方法是将玩家可以降落的所有对象放入一个数组中,然后检查玩家的 x 和 y 坐标以查看它们是否落入每个对象的框内。
例如:
您可能希望根据玩家的中间而不是左上角来计算它,在这种情况下,只需将玩家宽度的一半添加到其 x 位置,将其高度的一半添加到 y 位置。
It depends a lot on how your board is laid out. One way is to put all of the objects your player can land on into an array, then check the player's x and y coordinates to see if they fall inside of each object's box.
For example:
You may want to calculate it based on the middle of the player rather than their top-left corner, in which case just add half the player's width to their x position and half their height to their y position.
为了性能(并避免不必要的代码),如果它是基于图块/骰子,为什么不做这样的事情
板将是一个数组,并且在播放器中您可以使用 getters/setters 来“包装”板,如下所示
For performance (and avoiding unnecessary code), if it's tile based / dice why not do something like this
The board would be an array, and in Player you can use getters/setters to 'wrap' the board like this