除了在程序启动时之外,是否可以随时使用游戏线程启动 SurfaceView?
我已经阅读了几个示例程序和教程来尝试解决我的问题,但它们似乎都以相同的方式进行。我使用了几个 Activity 和 xml 文档来创建一个在游戏启动时加载的菜单。当用户单击“开始游戏”按钮时,它会加载一个新的活动,该活动使用我的游戏线程和所有游戏属性设置视图。我知道这个活动是有效的,因为我已经将它作为自己的项目单独运行,但是我尝试在菜单之后启动它的各种方式,我都会收到 nullPointerException 并且它会强制关闭。我阅读了 SurfaceViewOverlay 教程并尝试使用该实现,但我使用的是 SurfaceView,而不是 GLSurfaceView。我正在考虑重写我的整个程序以使用 OpenGL,但我想我会看看其他人是否知道我在这里做错了什么。如果您需要代码片段,我可以在此处粘贴一些代码片段,但这并不是真正错误的特定代码,我认为这是我使用(滥用)该语言的方式...
感谢您的帮助, 亚伦
I've read several example programs and tutorials to try and solve my problem but they all seem to go the same way. I've used a couple Activities and xml documents to create a menu that loads when my game starts. When the user clicks the "Start The Game" button, it loads a new Activity that sets the view with my game thread and all of the game properties. I know this activity works because I've run it alone as its own project, but every way I've tried to start it after the Menu, I get a nullPointerException and it force closes. I read the SurfaceViewOverlay tutorial and attempted to use that implementation, but I'm using a SurfaceView, not a GLSurfaceView. I'm debating rewriting my entire program to use OpenGL but I figured I would see if anyone else knows what I'm doing wrong here. If you need the code snippets I can paste some here, but it's not really the specific code that's wrong, I think it's the way I'm using(abusing) the language...
Thanks for any help,
Aaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很久以前就发现了我的问题,但我想我会回来并为其他遇到我的问题的人提供答案。使用 SurfaceView 时,它必须是创建它的活动的一部分,并且位于该活动的 xml 中的某种 FrameLayout 中。
例如:
您可以添加您想要的任何其他布局元素,但这是创建 SurfaceView 所必需的。我希望这对遇到我的问题的其他人有所帮助,如有任何进一步的问题,请提出,如有必要,我一定会详细说明。
I discovered my problem quite some time ago, but figured I would come back and give an answer to anyone else having my problem. When using a SurfaceView it must be part of the activity that created it and be in some sort of FrameLayout in the xml for that activity.
For example:
You can add any other layout elements you would like, but this is required to create the SurfaceView. I hope this helps anyone else who had my problem, for any further questions just ask and I'll be sure to elaborate if necessary.