我在每个 Android 图形/SurfaceView 教程中都遇到问题
我正在尝试学习如何在 Android 上制作视频游戏,因此我需要一些不错的教程来了解如何使用 SurfaceView 对象在 Android 上制作图形。然而,我尝试过的每一个图形教程(主要是 SurfaceView 的东西)都失败了。请注意,我不想使用 XML,因为它超出了我的范围,Google 只是想在整洁的广告中出售该技术,而我可以通过编程来实现这一点。
我遇到的一个主要问题是,有很多来自 Google 和第三方的教程,其中的代码使用 import android.opengl.GLSurfaceView 命令,或者导入 GLSurfaceView 子集,但这些代码在我的 IDE 上永远无法运行。每次我尝试导入其中任何一个包时,Eclipse 都会说它基本上无法识别该包。奇怪的是,我可以导入 android.opengl.*,尽管这仍然导致这些包中的某些代码引用无法识别的类型和/或方法。
在尝试解决第一个问题一段时间后,我注意到 Lunar Lander 示例没有尝试导入这两个问题库中的任何一个。因此,我将代码和参考资源提取到我的一个婴儿项目中,而该项目中的其他所有内容均未使用。当然,我确实更改了 Lunar Lander 代码所在的包,并更改了 LunarLander.java 或其他内容中的类名,但这应该不重要。我能够在 Eclipse 中构建这个东西。然而,当我去运行它时,它除了崩溃之外什么也做不了。在不显示任何月球着陆器图形或任何内容的情况下,模拟器只会给我这个错误消息,基本上说我的应用程序已意外停止工作并让我关闭该应用程序。
1) opengl.GLSurfaceView 包的问题如何处理? 2)月球着陆器的例子是怎么回事? 3) 哪里有关于如何制作 Android 视频游戏的好的、可靠的教程,
谢谢。
I'm trying to learn how to make video games on Android, and therefore I'm needing to get some decent tutorials going on how to make graphics on Android using the SurfaceView object. However every single graphics tutorial I've tried (mainly SurfaceView stuff) has failed. Please note that I don't want to use XML, as it is out of my element, and Google just wants to sell that technique on the advertisement of neatness, which I can do programmatically.
One major problem I've run into is that there are many tutorials, both from Google and from third parties, with code that uses the import android.opengl.GLSurfaceView command, or either imports a subset GLSurfaceView, and that never works on my IDE. Every time I try to import either one of those, Eclipse wants to say that it basically doesn't recognize that package. The strange thing is that I CAN import android.opengl.*, although that still causes some of the code in those packages to be referring to unrecognized types and/or methods.
After trying to fool around with the first problem for a while, I noticed that the Lunar Lander example didn't try to import either one of those two problem libraries. So I pulled the code and referenced resources for that into one of my infant projects, leaving everything else in that project unused. Of course I did change which package the Lunar Lander code was in and changed the class name in LunarLander.java or whatever, but that should not matter. I was able to get the thing to build in Eclipse. However when I went to run it, it would do nothing but crash. Without showing any Lunar Lander graphics or anything, the emulator would just give me this error message basically saying that my App has stopped working unexpectedly and makes me close the App.
1) What's the deal with the issues with the opengl.GLSurfaceView package?
2) What's the deal with the Lunar Lander example?
3) Where's a good, firm tutorial on how to make video games for Android
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在制作 2D 还是 3D 游戏?我不能谈论 3D,但我已经构建了一些简单的 2D 游戏,而 SurfaceView 更多的是一种障碍而不是帮助。模拟器仅模拟一个核心,因此您在绘图上并没有真正获得性能优势。此外,线程开销和维护是处理和阻止许多功能的痛苦(我花了几个小时试图从各种配置启动 GameOver 对话框,而额外的线程阻止了这种情况的发生)。
SurfaceView 的替代方法是实现您自己的扩展 View 的类,并重写 onDraw(Canvas) 来绘制您喜欢的任何内容(这就是我和我的朋友所做的)。
回答你的观点:
我从来没有从事过 3D 工作,也没有使用过 Android 的 OpenGL,但是 Eclipse(如果你正在使用的话)在定位 Android 资源方面可能有点不稳定。加载其余的类吗?
Lunar Lander 向您展示如何创建和销毁扩展 SurfaceView 和 SurfaceHandler 的视图。同样,在某些情况下 SurfaceView 可能是一个不错的选择,但如果您刚刚开始使用 Android 并构建简单的 2D 游戏,我认为它不是必需的。
好的教程很难找到。我花了几个小时阅读 这款 2D 游戏 “http://pragprog.com/titles/eband3/hello-android” rel="nofollow noreferrer">Hello Android。
我和我的一些朋友这学期正在开发 Android 游戏,我们还建立了一个博客我们希望随着学期的进行,为其他人提供资源。遗憾的是,目前还没有太多相关内容。
祝你好运!
Are you building games in 2D or 3D? I can't speak for 3D, but I've built some simple 2D games and SurfaceView was more a hindrance than a help. The emulator only simulates one core, so you don't really get a performance benefit on the drawing. Furthermore, the thread overhead and maintenance is a pain to deal with and prevents many capabilities (I spent a few hours just trying to launch a GameOver dialog from various configurations, and the extra thread prevented this from happening).
An alternative to SurfaceView would be to implement your own class that extends View, and override onDraw(Canvas) to draw whatever you like (this is what me and my friends did).
To answer your points:
I've never worked in 3D or used Android's OpenGL, but Eclipse (if that's what you're using) can be a bit temperamental with locating Android resources. Do the rest of your classes load?
Lunar Lander shows you how to create and destroy a view extending SurfaceView and SurfaceHandler. Again, there may be contexts for which SurfaceView is a great choice, but if you're just starting with Android and building simple 2D games, I don't think it's essential.
Good tutorials are hard to find. I learned enough to make this 2D game from spending a few hours with the e-book version of Hello Android.
Some buddies of mine and I are working on games for Android this semester, we've also set up a blog that we hope to make a resource to others as the semester goes on. Sadly, there's not much on it at the moment.
Good luck!