[英]How to draw background image and make it looks similar on all Android devices?
Looking for advice with the next problem. 寻找下一个问题的建议。 I am developing small game and I have a *.png file for background.
我正在开发小型游戏,但是我有一个* .png文件作为背景。 I need to put it to background of the main game screen.
我需要将其放在游戏主屏幕的背景上。 Moreover, it has to bee 2 times bigger in width and 1.5 times bigger in height as the screen's sizes, because my objects "flight" across these borders.
此外,它的宽度和屏幕高度必须比屏幕尺寸大2倍,高度要高1.5倍,因为我的物体“飞越”了这些边界。 Additionally the screen is moving around this background in a gameplay.
此外,屏幕还在游戏中围绕此背景移动。 But I have stuck a bit on how to do it.
但是我对如何做到这一点有所保留。
I want my background to look similar on all screens with different sizes and densities. 我希望我的背景在所有尺寸和密度不同的屏幕上看起来都相似。 I have tried some solutions but I don't like them, or I have made something wrong:
我尝试了一些解决方案,但是我不喜欢它们,或者我做错了什么:
Make different background images and put them in special folders. 制作不同的背景图像,并将它们放在特殊的文件夹中。 It sounds good, but with the amount of resolutions of Android devices in the market it is not sounds good for me.
听起来不错,但是鉴于市场上有很多Android设备的分辨率,这听起来对我来说并不好。 It will just make the size of *.apk bigger.
它只会使* .apk的大小更大。 And if I will use the methods to set background it will stretch the image - not a good idea I think.
如果我将使用这些方法设置背景,它将拉伸图像-我认为这不是一个好主意。
In the onDraw()
method draw the image on canvas. 在
onDraw()
方法中,在画布上绘制图像。 I have to put it's top-left corner to the most top-left corner of the possible game area and draw it. 我必须将其左上角放置到可能的游戏区域的最左上角并进行绘制。 But, here is some options:
但是,这里有一些选择:
So, the question is: what is the best option for drawing background for the game screen when you need it to be almost twice bigger than the screen's size, make it looks same on all devices and move the screen around when the game is played? 因此,问题是:当您需要为游戏屏幕绘制背景尺寸几乎是屏幕尺寸的两倍时,使它在所有设备上看起来都一样并且在玩游戏时将屏幕四处移动时,绘制背景的最佳选择是什么?
you should use 9 patch image . 您应该使用9个补丁图像。
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background. NinePatchDrawable图形是可拉伸的位图图像,Android会自动调整其大小以适应将其放置为背景的View的内容。
see this link. 看到这个链接。 http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.