Android SurfaceView 中的分辨率独立性
我目前正在 Android 中启动一个游戏引擎,首先涉足该平台并具备基础知识,但是我不确定在使用 SurfaceView 绘制图形时实现分辨率独立性的最佳方法。
寻找关于如何保持游戏/精灵等在屏幕上看起来相同的指针,显然,缩放每帧的所有精灵或存储不同分辨率的许多变化是没有效率的
I am currently starting a game engine in Android, first foray into the platform and have the basics in place however i am unsure of the best way to approach resolution independence when using SurfaceView to draw graphics.
Looking for pointers as to how to keep the game / sprites etc all looking the same independent of the screen, obviously it wouldn't be efficient to scale all the sprites every frame or store many variations for differing resolutions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需在加载精灵时缩放它们即可。我猜你是从资源中将它们作为位图加载的,对吗?如果是这种情况,那么您需要做的就是这样:
其中比例基于屏幕尺寸的变化。
You'd just scale the sprites when you load them. I am guessing you're loading them as Bitmaps from a Resource, right? If that's the case then all you need to do it something like this:
Where scale is based on the change of the screen size.
有两种简单的方法:
第一:
在创建 Surface 视图时,它调用:
创建一些全局变量 x 和 x 。 y 因此,如果您使用以下命令覆盖它:
那么在任何绘图或游戏计算中,您可以使用窗口 w 和 h。
第二:
调用 getWidth() & getHeight() 在绘图和游戏计算中。
祝你游戏愉快!
There are two simple approaches:
First:
On creation of a Surface view, it calls:
Create a few global variables, x & y so if you override this with:
Then in any drawing or game calculations you can use the window w and h.
Second:
call getWidth() & getHeight() in drawing and game calculations.
Good luck with your game!