I use SurfaceView for my 2D Android game which I have almost completed. It's based on JBox2D. It is perfectly running on Samsung Galaxy S2, its FPS is 60. It is also running smoothly on HTC Explorer, its FPS is about 54. I thought that if my game was working well in these relatively old devices, it would be working better in the newer ones. But I was wrong! I saw yesterday the FPS value of my game on Galaxy Note 4 is varied between 22 and 45 depending on the number of game objects.
After investigating on this issue in Google and StackOverflow, I deduced that the new devices like Galaxy Note 4 which has higher resolutions (1440 x 2560) could not handle with their large images whereas the little ones can handle with their own smaller images (Galaxy s2:480 x 800, HTC Explorer:320 x 480). Yes, the new devices are surely faster than the older ones, but I think their huge resolutions of the newer devices are the reason of the slowness on the SurfaceView. Of course, this is valid under SurfaceView conditions. If I used OpenGL for my game, it would not be a problem for the new devices having high resolutions.
My bitmaps are designed for 800 x 1280 devices. According to the different device resolutions, my game rescales the images when they are loaded at the beginning of the each level by using createScaledBitmap.
I couldn't transform my game from SurfaceView to OpenGL platform because my game is about to finish and I didn't have enough knowledge about OpenGL.
What should I do?
I believe you have correctly identified the problem: newer devices have pixel counts like you'd find on a 27" monitor (2560x1440), because the manufacturers are chasing screen resolution like they do camera megapixels. The result is that rendering a full screen takes longer, especially when you're doing it in software. Faster CPUs and increased bus bandwidth can help, but full-screen software rendering is problematic.
The solution for Android is to make the Surface smaller, and let the hardware scale it up as it's being scanned out. This is significantly easier (and more efficient) than scaling up each individual item. You do this with the SurfaceHolder#setFixedSize() method. For example, for a 2560x1440 display, you could set the Surface size to 1280x720, and only render a quarter of the pixels. The display performs the pixel doubling (with bilinear filtering).
You can find a blog post here, and can see this in action in Grafika's "hardware scaler exerciser" activity (youtube demo video).
The various examples use GLES -- which also benefits from having fewer pixels to fill -- but applies to Canvas rendering as well.
Related
I'd like to know, how can I select the best resolution to build a 2D game in android?
You can go with 1920*1080 - this will give you a clear output on most current devices - and use FitViewPort or ExtendViewPort as you wish.
I'm rendering my graphics in 2K resolution (i.e. in 3040 x 1,40 - aiming most popular high-end phones of today, i.e. Samsung S10) so it will definitely look well on screens with higher resolution. And then I'm using camera zoom to display it properly on current screen resolution. It does take a bit more space for graphics and it's probably loosing some frame per second but on today's devices it's acceptable loss. My games run smooth even on older devices, so I don't think it's an issue at all.
I have made an app which works well on iOS but has performance problems on Android. I have noticed that on older devices such as galaxy s2 with a low screen resolution, the app is fine. It only lags on the new hd devices such as the galaxy s4 and nexus 4.
Are high screen resolutions causing the devices to lag?
Does anyone know what I can do to find out how to fix this?
It's really strange because it's only on the new devices.
Not sure why it is happening on the S4 since it has a decent CPU and GPU, but high-density screens will cause lag, especially in Flash-based apps. I ran into the same problems when trying to move from the iPad 2 to the retina displays.
Let's look at it this way, with regards to the iPad issue I had. The iPad 3 bumped the resolution from 1024x768 to 2048x1536. That is 4x as many pixels. Traditionally, Flash has issues rendering vector images. It is good at it, among the best, but it is slow. So rendering a vector object on the iPad 2 was only a 40x40 area to update. On the iPad 3, it is a 160x160 area to update.
Quick tips:
Never use CPU rendering. Stick to Direct (or GPU if you need to, but you lose features with GPU rendering, such as filters)
Decrease the amount of vectors being used and how often you are changing them. You should avoid, at all costs, updating vector objects every frame.
Make sure you are testing a release build (In Flash Builders, Project->Export Release Build...) when testing framerate issues. It is generally much more evident on the iOS side than the Android side, but debug builds do cause lag
Don't set the framerate higher than you have to. As the framerate goes higher, each frame has less time to run the necessary calculations. The lag you notice isn't truly from low framerates (though that doesn't help), but more from dropped frames when a frame takes longer than available to render. 24 is the default, 30 is the standard. 60 is the max and is always nice, but it is completely unnecessary unless you are making a game.
I have several apps in production right now that run just fine on my Nexus 5, which is the same resolution as the S4 with roughly the same hardware, spec-wise. Unless there is a problem with that hardware specifically, you should be able to manage 30fps no problem, if not 60.
use direct render mode it is recommended by adobe.
I'm not sure if this is the best place for this question, if not please point me the right one!
I am scaling my app for multiple resolutions and I've come across this two pages
Look on Scren Sizes and densities, the chart says 17% of the devices are normal/xhdpi, also here, in the Table 3 it says that normal/xhdpi is 640x960.
I know this is the Iphone resolution, running searches on google and gsmarena and I can only find iPhones and some android devices yet to be released.
So my question is among tablets and phones, already in the market, is there any android device with this resolution? If not, why is that resolution in that table?
Thanks!
EDIT
So according to the answers there are no devices with that resolution, but if there are no android devices with that resolution, which ones fit in those 17% with normal size and xhdpi? Why is that even on the chart?
Normal/xhdpi is the bucket that the Galaxy Nexus and all other 720p (1280x720) normal sized phones fall into. 720p has become a popular resolution for high end Android phones which is why you see 17% in that bucket. The 960x640 resolution you see listed is just the minimum resolution to be considered xhdpi with a normal size screen. It doesn't necessarily mean that there are phones with that resolution.
It's kind of obscure, but this seems to count:
http://en.wikipedia.org/wiki/Meizu_M9
...unless you're looking for Western phones. Never seen one in real life, though. My own personal big list of wacky Android devices doesn't show any 640x960 screens, but I have encountered a 540x960 one.
Current resolutions in Arc/Neo/Pro/Play & S2 are good... higher resolution will surely increase the sharpness of images and the whole UI duo to the higher ppi but it will have negative impacts too
1- small difference in battery life... this is small enough to just ignore
2- lower performance in 3D games and UI rendering...
the iPhone 4 GPU it self ( SGX 535 ) is slower than the Adreno 205, and it also uses higher resolution this is why 3D games dev. have to sacrifice quality to have playable fps...
currently the fastest GPU is SGX 540 ( used for example in OMAP 4430, in the heart of Optimus 3D )... and Tegra 2 which is a little bit slower than SGX 540.. and btw Tegra 2 by it self is a whole SoC and not just a GPU.. but it uses nV own GPU and no one else is using it.. and they cost more than Adreno 205 based SoC ( this what makes Adreno 205 more mainstream in the high-end )... but both of these GPU's are still not powerful enough to give 30 - 40 fps in high resolution like 960x640
so next year when the new or newer GPU's becomes mainstream and cost same as what todays Adreno 205, SGX 540 cost's then we may see higher resolution that can be used without sacrificing performance... but don't expect a direct jump between 854x480 to 960x640, there's a hell a lot of pixels there to compute and screen panel makers tend to have a control hand here too... the close one is Atrix which has 960x540 ( 100px less in width than iPhone 4 ) and it uses Tegra 2.
EDIT : Just found this! Sharp IS03 has a 960x640 resolution. But, unfortunately it has been released only in Japan.
Check these links for more info on it : link1 , link2, link3.
I'm trying to develop an app that uses opengl on android, and ideally make it run on any phone as old as the original droid (or at least any phone that has OpenGL ES 2.0 support). Currently, I'm using a 2048x2048 ETC1 texture compression. It works fine on the Droid X I'm testing it on, but I currently don't have an original droid to test it on, and I can't find much data on this topic either. I know the G1 didn't do well with textures bigger than 512x512, and the droid seems to do fine with images as large as 1024x1024, but what about 2048x2048? (Again, etc1 compression, so it's about 2 MB large). Also, because ETC1 doesn't support alpha, I would like to load up another ETC1 texture to support an alpha channel. Is this a pipe dream?
Basically, I would like to know how much space I have to load texture data in android phones no older than the original droid, at least without the whole thing slowing down drastically.
You can query the MAX_TEXTURE_SIZE to get the maximum texture size, or you can look up your phone on http://glbenchmark.com (you can find the Droid info here). The G1 did not support GLES 2.0, AFAIK.
Loading up several textures should definitly work, especially when they are not more than 2 MB each. But you will of course be restricted by the size of the memory available.
Also, to have optimal performance you should mipmap your textures. Since you are using ETC, this must be done offline.
For a guide to how to use ETC1 with alpha, see here.
My Android app has been out for several months and works fine on any number of WVGA phones like the Droid, Droid 2, Galaxy, etc.
On the Motorola Xoom, however, a small portion of the textures load with white boxes where the images should be.
Researching online the most usual cause for this appears to be not using power of two textures. This seems an unlikely explanation since they work fine on so many other devices. Also, I am using power of two textures. The one caveat there is that I'm loading a bunch of bitmaps into a 1024 by 1024 texture dynamically. The code I'm using is from a now defunct library called Rokon, the relevant texture atlas code is here: http://code.google.com/p/rokon/source/browse/trunk/src/com/stickycoding/rokon/TextureAtlas.java?r=260 -- Like I said, I'm skeptical this could be the cause since it works on so many other devices AND many of the textures I am loading this way do work fine.
But I'm not sure what else could be causing it. A memory issue seems unlikely given that amount of memory available on the Xoom compared to the other devices the app works on.
Right now I don't own a zoom, but I can replicate the issue via DeviceAnywhere (where I see white backgrounds).
Nothing of interest shows up in LogCat either.
I know this isn't much to go on, but I'm at a loss here, what kinds of potential causes should I be looking at here? Thanks in advance for any ideas.
Try using glGetError() to see if OpenGL throws any errors
Is your application 2D or 3D? When you're drawing your sprites on the screen; which method are you using?
If your texture is white during onDrawFrame that probably depends on:
An untextured quad (using VBO:s or standard Vertex Arrays) - probably not, because it works on other devices
Xoom lacks support of the draw_texture extension - if you're using 2D
Xoom lacks support of VBO:s (Vertex Buffer Objects) - probably not, almost every Android device out there supports VBO:s
Do you have any sort of texture compression implemented that Xoom doesn't support?
At runtime, use this code to get the extensions and check if they're available:
String extensions = gl.glGetString(GL10.GL_EXTENSIONS);
boolean supportsDrawTexture = extensions.contains("GL_OES_draw_texture");
// Continue here and sooner or later you should see where Xoom lacks support
// where other devices doesn't.
Is it possible that you're falling foul of Android's automatically-resize-bitmaps behaviour? Print out the bitmap sizes as they are loaded to check, or move them to res/drawable-nodpi to avoid the behaviour entirely.
Is it possible that your texture exceeds 2048 pixels width or height? That's the maximum allowed texture size on XOOM.