Corona SDK (Lua) 如何动态/随机生成关卡
就像在这个应用程序中一样。
http://www.youtube.com/watch?v=FdaTyLrNYOo
我看到了精灵保持在同一 x 轴上并且水平仪向左移动。
platform = display.newRect(0,500,400,10)
physics.addBody(platform, "static")
platform.rotation = 0
^那是为了创建一个平台。
平台是如何即时生成的?
Like in this app.
http://www.youtube.com/watch?v=FdaTyLrNYOo
I see the sprite is kept on the same x axis and the level moves to the left.
platform = display.newRect(0,500,400,10)
physics.addBody(platform, "static")
platform.rotation = 0
^that is for creating one platform.
how is the platform generated on-the-fly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题最好不要在代码级别上解决,而是在更高的设计级别上解决。您已经考虑过要使用哪种算法来创建平台。
有多种选项,每种选项都有特定的优缺点:
完全随机:您可以使用完全随机的平台高度和长度。这很容易实现,但结果也是随机的,可能无法解决。
正弦波:您可以使用
sin()
函数为您的关卡生成变化的高度。这也很容易实现,并且与随机相比可能会产生更好的游戏结果。危险在于它可能太容易玩而变得无聊。当然,您可以使用组合技术或任何其他类型的数字生成器。
This problem is best not addressed on the code level but on a higher design level. You have think through what kind of algorithm you want to use to create the platforms.
There are several options, each with specific pros and cons:
Completely random: You can use completely random platform heights and lengths. This is easy to implement but the results are also random and might be impossible to solve.
Sine waves: You could use the
sin()
function to generate altering heights for your level. This is also easy to implement and might produce better gameplay results compared to the random. The danger is that it might be too easy to play and become boring.Of course you can use a combined technique or any other sort of number generator.