当我要在我的游戏扩展位图 [英] When should I scale Bitmaps in my game

查看:164
本文介绍了当我要在我的游戏扩展位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用了Android开发我的第一场比赛 SurfaceView

I've just started developing my first game with Android using SurfaceView.

我扩展我的位图 s到支持不同的屏幕尺寸。但我不知道这是否加载位图或把他们拉来画布使用矩阵。

I scale my Bitmaps to support different screen sizes. But I don't know if it's better to do the scaling when loading the bitmaps or when drawing them to Canvas using Matrix.

我想第一个会占用更多的内存,但它的性能更好。但我不知道事情如何真正工作在这里,所以专家的任何建议将AP preciated。

I guess the first one would occupy more memory but it's better in performance. But I don't know how really things work here so any suggestion from experts would be appreciated.

推荐答案

做的最好的事情是不能扩展位图都没有。你可以只缩放SurfaceView的表面来代替。

The best thing to do is to not scale the Bitmaps at all. You can just scale the SurfaceView's surface instead.

见一个例子,硬件缩放练功,在 Grafika 和的这个帖子一个解释。其基本思路是调用像 surfaceView.getHolder()setFixedSize。(1280,720)设定表面的大小1280×720,然后总是呈现为如果显示是720P。硬件将其扩展到任何当前屏幕尺寸。

See the "hardware scaler exerciser" in Grafika for an example, and this post for an explanation. The basic idea is to call something like surfaceView.getHolder().setFixedSize(1280, 720) to set the surface's size to 1280x720, and then always render as if the display were 720p. The hardware will scale it to whatever the current screen dimensions are.

这是稍微复杂多了 - 你想选择一个大小的屏幕显示比例让你的东西不会显得捉襟见肘(这是你必须处理在Android反正)相匹配。 Grafika这样做是为了确保该广场仍然广场。

It's slightly more complicated than that -- you want to pick a size that matches the display aspect ratio so your stuff doesn't look stretched (which is something you have to deal with on Android anyway). Grafika does this to ensure that the square remains square.

此方法是的的更高效的CPU和内存消耗比缩放单个位图。

This approach is much more efficient in both CPU and memory consumption than scaling individual bitmaps.

这篇关于当我要在我的游戏扩展位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆