碰撞就为了这个?
如果您观看我游戏的此链接:
http://www.youtube.com/watch?v= HMWl8D_OwyM
如果你看这个,你会看到角色可以走到任何地方。我想添加一些碰撞,这样他就只能在路上行走。是否有一些可能的方法可以在不制作将其加载到数组的碰撞.txt?
或者我该如何以最好的方式解决这个问题? (关卡是从图片中加载的)
If you watch this link of my game:
http://www.youtube.com/watch?v=HMWl8D_OwyM
If you watch this you will see the character can walk anywhere.. I want to add some collisions so he can only for example walk on the roads.. Is there some possible way to make this without makining a collision .txt that loads it up to an array??
Or how would i solve this the best way?? (The level is loaded from a picture)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果关卡是纹理,您可以对纹理进行采样,以允许角色仅在某些表面上行走;或者对纹理进行采样,以允许角色仅在某些表面上行走。或者您可以创建一个单独加载的碰撞遮罩并纯粹用于碰撞检测。
如何实施取决于您;定义一个替代数据结构来包含所有碰撞对象的边界框可能是最简单的(也是最高效的)。
编辑:
逆向可能是更简单的方法;不要定义对象,而是定义角色可用的路径。这将严重限制自由漫游能力,但对于您的示例来说可能是理想的选择。
EDIT2:
这些都不是简单的解决方案:重新考虑关卡数据可能会更好;不要只使用位图,也许可以考虑一个简单的基于图块的解决方案。
这将允许更容易地区分表面、纹理和物体;因此,碰撞检测。
If the level is a texture, you either sample the texture allowing the character to only walk on certain surfaces; or you can create a collision mask that is loaded separately and used purely for the collision detection.
How you implement this is up to you; and it may be simplest (and most productive) to just define an alternate data structure to contain the bounding boxes for all your collision objects.
EDIT:
The inverse may be the easier approach; instead of defining your objects, define the paths available to the character. This will severely limit free roam ability, but may be ideal for your example.
EDIT2:
These aren't easy solutions: it may be better for you to re factor your level data; don't just use a BITMAP, perhaps look at a simple tile based solution instead.
This would allow for easier distinction of surfaces, textures, and objects; and therefore, collision detection.