创建一个随机的正弦图,如风景精灵
假设我有这个精灵:
我在运行时创建了一个随机景观:
然后,我想用精灵平铺线下方的区域:
这是游戏场地,因此它也应该是一个物理对象(在 Box2D 中)。
在这里,他给出了如何使其成为物理体的示例。那么,如何在代码中完成图形部分呢?
编辑:查看 AndEngine 示例,文件 RepeatingSpriteBackgroundExample.java,这不完全是我需要的,但我应该坚持这个想法并改变RepeatingSpriteBackground 类 满足我的需要?不过,我认为这不是最好的方法......
提前致谢。
Lets say I have this sprite:
And I created a random landscape during runtime:
And then, I want to tile the area below the line with the sprite:
This is the game ground, therefore it should also be a physics object (In Box2D).
Here, he given a sample of how to make this a physics body. So, how do I do the graphics part in code?
EDIT: Looking in the AndEngine examples, file RepeatingSpriteBackgroundExample.java, it's not exactly what I need but should I stick to this idea and change the RepeatingSpriteBackground class for my needs? I don't think that would be the best method however...
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太了解 Box2D 或 AndEngine,但我认为这是一个有趣的问题,并制作了一个自定义 SurfaceView,它可以绘制随机“地形”,就像您图片中的那样。 (希望它对您或其他人有用,至少我学到了一些新东西:p)
单色地形:



平铺背景地形:
平铺位图:
我的代码如下:
如果这对您有任何帮助,您可能需要尝试一下参数来获取适合您需要的形状,并且很可能添加点之间的最小距离等参数。
稍微优化背景的绘制也是一个好主意,例如从底部向上绘制到地形的最大高度,以尽量减少对不可见区域的绘制。我还应该可以减少对 getHeight() 和 getWidth() 的调用量。
干杯!
I don't really know about Box2D or AndEngine, but I thought this was an interesting problem and made a custom SurfaceView that can draw a random "terrain" like the one in your picture. (Hopefully it will be of use to you or someone else, at least I learnt some new stuff :p)
Single colour terrain:



Tiled background-terrain:
The tiled bitmap:
My code is as follows:
If this is of any help to you you'll probably have to play around with the parameters to get shapes that suits your needs and most likely add a parameter for minimum distance between points etc.
It is also a good idea to optimize the drawing of the background a bit, like drawing from the bottom up to the maximum height of the terrain, to minimize drawing to invisible areas. I should also be possible to reduce the amount of calls to getHeight() and getWidth().
Cheers!