Mahesh
Mahesh

Reputation: 3997

Android Game working differently in different Android Phone

i recently developed a game, for Android 2.3.3, and strangely im finding few weird behaviour in different phones,

for example

  1. An explosion sprite(256x256 pixels) divided into 4x4=16 images, when displayed is being displayed as a 2x2 image in Samsung Galaxy Ace 2.3.3 and Samsung Galaxy Y, 2.3.5 ,

  2. Also, the accelerometer works in a haphazard form in Sony Xperia 2.3.3 and Samsung Galaxy Ace.. either its too slow(and takes touch gestures after 3-4 second gap) and Android OS throws a Alert box saying, the app is not responding, else its too fast.

Strangely, The game works perfectly on a Samsung S2, just like it plays on the VirtualBox..

please help me, b'cos this is my college project, and I wont even be able to put this up in the market if such a queer problem exists!!

Thanks in Advance!!

Upvotes: 2

Views: 170

Answers (2)

nitroglycerine
nitroglycerine

Reputation: 171

I think I have the same experience with the graphics problem:

From your code, I'm guessing you may have pre-computed "width_explosion" and "height_explosion" from the image height/width you have seen in an image editor and using the same values on different devices.

The device you have listed have two different DPI values as Android knows: 240, or MDPI (Galaxy S2) and 120, or LDPI (Galaxy Ace and Galaxy Y). Note that Galaxy S2's DPI is exactly twice as Ace's and Y's.

Android makes it handy for app authors by assisting them in manipulating images. When images are read from resources through getDrawable and are ready for rendering on screen Android resizes the images with respect to 160DPI, so that they will have the same length measured with a ruler on screens with different pixel densities. For example, if an image with 128x128 pixels is 2cm long and 2cm wide on Galaxy S2, it should be 2cm long and 2cm wide on a Galaxy Ace. However, to cover the more pixels on a Galaxy S2, it's resized to 192 x 192 pixels when drawing on a Galaxy S2, because its DPI as the Android system knows it is 240, 1.5 times the DPI of an ADP1 (HTC Dream). Similarly, the image will be resized to 96 x 96 on a Galaxy Ace or Galaxy Y.

The source rectangle in canvas.drawImage, unfortunately, refers to the number of pixels in the resized bitmap. That means the same source rectangle used in your code sample covers 4 times as many pixels on a Galaxy Y as it does on a Galaxy S2. I guess you are describing in the question that "the same sprite file looks like it was divided in 2x2 on a low DPI device but it should be divided by 4x4".

The following example illustrates what happens when I'm trying to replicate your question with devices with different DPIs. I cannot post images, so I have put the images here (it's my blog):

http://edgeofmap.com/blog/2013/05/android-bitmap-over-devices-of-different-dpis/

Upvotes: 1

Timothy Swartz
Timothy Swartz

Reputation: 194

Not sure what to do about the graphics issue, but for the accelerometer each device acts differently. Use event.sensor.getMaximumRange() in your onSensorChanged() to get the maximum value and base your actions on that or a percentage of that.

Upvotes: 0

Related Questions