java android上的Java侧滚动游戏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3058868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:08:53  来源:igfitidea点击:

Java side scrolling game on android

javaandroid

提问by hanesjw

I'm trying to make an easy side scrolling game just to learn the ropes of game programming on android. I came up with a solution of how to make it but I don't really think it is the most elegant solution. I wanted to get some different ideas on how to implement my game, as I really have no other solution right now.

我正在尝试制作一个简单的横向滚动游戏,只是为了学习在 android 上进行游戏编程的技巧。我想出了一个如何制作它的解决方案,但我并不认为它是最优雅的解决方案。我想就如何实现我的游戏获得一些不同的想法,因为我现在真的没有其他解决方案。

Here is a quick explanation of how it works..

这是它如何工作的快速解释..

I basically have blocks or objects fall from the top of the screen. The blocks are defined from a pre-defined string I create using a custom 'map-editor'.

我基本上有块或物体从屏幕顶部掉下来。这些块是根据我使用自定义“地图编辑器”创建的预定义字符串定义的。

I create all the blocks at compile time, position them on or off the screen and simply increment their coordinates with each iteration of the gameloop.

我在编译时创建所有块,将它们放置在屏幕上或屏幕外,并随着游戏循环的每次迭代简单地增加它们的坐标。

It is actually done a little bit better then that, but that gives a short easy explanation on the basic idea.

它实际上做得比那个好一点,但这对基本思想给出了一个简短的简单解释。

I heard from a few people that instead of incrementing each block position, have the blocks stay there and simply change the viewable area. That makes sense, but I have no idea how to do it.

我从一些人那里听说,不要增加每个块的位置,而是让块留在那里并简单地更改可视区域。这是有道理的,但我不知道该怎么做。

Can anyone share some ideas or links on how I can implement something like this? I know my current solution isn't the greatest.

任何人都可以分享一些关于我如何实现这样的东西的想法或链接吗?我知道我目前的解决方案不是最好的。

Thanks!

谢谢!

回答by jqpubliq

For learning the ropes for game programming on android I would point you at Google I/O 2009 - Writing Real-Time Games for Android I/O session from last year and thisone from the 2010 sessions.

对于刚入门的游戏编程在Android上我想指出,你在谷歌I / O 2009 -写作实时游戏Android的I /去年O会话和一个从2010年的会议。

People telling you about changing the viewable area are probably assuming you're using OpenGL ES, which you might not be, but probably should consider.

告诉您更改可视区域的人可能假设您正在使用 OpenGL ES,您可能不会,但可能应该考虑。

回答by Bob Montgomery

If the blocks/objects are independent from each other, I'd continue to treat them as independent objects and update their position separately. After all, you may wish someday to make some of them move differently from each other. In game development, it's good to leave the engine as flexible as you can for as long as you can - polishing a game involves a lot of playtesting and fine-tuning of the mechanics of the game, and the more things you have to tweak the more polished you can get it. Optimize only if necessary.

如果块/对象彼此独立,我会继续将它们视为独立的对象并分别更新它们的位置。毕竟,您可能希望有一天让它们中的一些移动方式彼此不同。在游戏开发中,尽可能让引擎尽可能灵活是件好事——完善游戏涉及大量的游戏测试和游戏机制的微调,你需要调整的东西越多更精致,你可以得到它。仅在必要时进行优化。

But if the blocks aren't independent, and won't be, changing the viewing area rather than moving each block may be a good idea, though more information about your game would help - is it a platformer? A shooter? If there is some kind of player-controlled object on the playfield you'll have to change its position to keep it onscreen as you change the viewable area, which may make things overly complicated. It's hard to advise without more details.

但是,如果块不是独立的,也不会是独立的,那么更改查看区域而不是移动每个块可能是个好主意,尽管有关您的游戏的更多信息会有所帮助 - 它是平台游戏吗?射手?如果游戏场地上有某种玩家控制的对象,您将不得不在更改可视区域时更改其位置以将其保持在屏幕上,这可能会使事情变得过于复杂。如果没有更多细节,很难给出建议。

Good question, though!

不过好问题!

EDIT:

编辑:

Following your comment, and I saw your other question Problem decrementing in Java with '-='; I think I understand your question a little better - the main thing I'd change, from a design point of view, would be to create the blocks as needed, rather than creating all of them at once. In other words, create the blocks on the frame before they are going to appear on the screen and, once they are off the screen, delete them. Unless the game design calls for a large persistent world, of course - but it doesn't sound like that kind of game. Can the player backtrack, or do you allow only one-way scrolling?

按照您的评论,我看到了您的另一个问题Problem decrementing in Java with '-='; 我想我更理解你的问题 - 从设计的角度来看,我要改变的主要事情是根据需要创建块,而不是一次创建所有块。换句话说,在它们出现在屏幕上之前在框架上创建块,一旦它们离开屏幕,就删除它们。除非游戏设计需要一个大而持久的世界,当然——但这听起来不像那种游戏。玩家可以回溯,还是只允许单向滚动?

回答by nuriaion

Replica Island (http://code.google.com/p/replicaisland/) is a open source Jump & Run game on Android. (It's from the guy who made the Writing Real Time talks) Maybe you can get some good Ideas from it.

Replica Island ( http://code.google.com/p/replicaisland/) 是 Android 上的开源 Jump & Run 游戏。(来自制作实时写作演讲的人)也许您可以从中获得一些好主意。