Android游戏开发-关卡进展方法

发布于 2024-10-18 09:59:18 字数 523 浏览 5 评论 0原文

我目前正在开发一款类似于经典街机太空射击游戏的 Android 游戏。到目前为止,我几乎已经完成了所有事情,但是我的代码不太符合我的喜好,我正在尝试找出如何改进它。

我遇到的问题是敌人和其他物体进入屏幕。

目前我正在使用一个传递给线程的 Runnable 对象,在这个 Runnable 中是一个包含所有距离的数组,这些距离将触发新的敌人从屏幕的顶部或侧面进入。在 run() 方法中,我检查时间,如果 System.uptimeMillis() 大于或等于数组中的某个元素,我会触发另一个方法,该方法使用 switch 语句来确定要运行的事件。

这一切都变得管理起来相当麻烦,这就是为什么我想知道是否有人知道一种更有效、更简洁的方法来管理排队的敌人。

另外,我创建的数组包含 200 个左右的对象,一旦它们离开屏幕,我就会将它们清空。显然,对于一个性能良好的游戏来说,GC 的触发频率太高了。重新使用被摧毁或离开屏幕的敌人是不是最好?或者还有更好的方法吗? (我只是确保我的程序在进入市场之前是最好的)

提前谢谢您,

-Roflha

I am currently developing an Android game that is similar to a classic arcade space shooter. Thus far I have almost everything finished, but my code is not quite to my liking and I am trying to find out how to improve it.

The problem I am having is with enemies and other objects entering the screen.

Currently I am using a Runnable object that I pass to a thread, and in this Runnable is an array of all of the distances that will trigger new enemies to come in from the top or sides of the screen. In the run() method, I check the time and if the System.uptimeMillis() is greater than or equal to an element in my array, I fire another method that uses a switch statement to determine the event to run.

This is all becoming quite a hassle to manage and that is why I was wondering if anybody know of a more efficient and neater way to manager the queued enemies.

Also, my array I create is of 200-some objects and once they are off the screen I was nulling them. Obviously this was firing of the GC too often for a well-performing game. Is it best just to reuse enemies that are destroyed or go off screen? Or is there a better way for this as well? (I am just ensuring that my program is the best it can be before it ventures into the wilds of the Market)

Thank you in advance,

-Roflha

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

污味仙女 2024-10-25 09:59:18

我建议您查看此代码参考。它有一个很好的方法来处理物体、碰撞等。

它是由谷歌员工写的,出于某种原因听起来总是很酷。

I suggest you look at this code for reference. It has a good way of dealing with objects, collisions and stuff.

And its written by a google employee which always sounds cool for some reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文