Image sheet on physical mobile phones loses its quality

Hello! I have this code to have an image sheet. Photo quality is good on all types of virtual simulator phones.

But image sheet on physical mobile phones loses its quality.


local sheetOptions = {
    width = 300,
    height = 300,
    numFrames = 32,
    sheetContentWidth = 9600,
    sheetContentHeight = 300

local ballSheet = graphics.newImageSheet( "images/alefba/sheet.png", sheetOptions )
local ball = display.newSprite( ballSheet, { name="balls", start=1, count=sheetOptions.numFrames } )

ball.x = display.contentCenterX
ball.y = display.contentCenterY+20


<< image sheet dimensions: 9600*300>>
This is a sheet image that looks bad:

This is while another image sheet with a lower number of frames in in another part of the program has very good quality in the simulator and the physical phone.
This is a sheet image that looks good:

Does anyone know where this problem comes from?

Hi @arefeh,

I’m not sure your sheet should be so width.

EDIT: Try rearrange frames in sheet like 8x4 instead of 1x32.

Have a nice day:)

1 Like

Looks like @ldurniat beat me to it, but some explanation.

You won’t see this directly unless you write shaders, but when looking up pixels in a texture you basically provide coordinates like x / width and y / height, numbers that usually lie between 0 and 1.

Mobile hardware is supposed to allow increments of 1 / 1024 in that range to be exactly represented. (See the bit with mediump and FP Precision on the right side of page 3, here if interested.)

Anything else gets rounded. This isn’t too bad if the denominators are close. But you can imagine with x / 9600…


Also, there’s a matter of texture memory usage.

Texture memory usage is calculated as width * height * 4 / 1024^2 where width and height are rounded up to the nearest power of two value, i.e. 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, etc. If you have an image that is 1025 pixels wide, it gets treated as 2048.

Your sheet is 300x9600, so it gets treated as 512x16384, which adds up to 32MB. You should ideally try to stick to images/sheets that are no larger than 2048x2048 (16MB), because otherwise you may encounter OutOfMemoryError on some Android devices. You can use large heap to bypass that limit, but it isn’t encouraged.

1 Like

Thanks for your help. Converting photos to 8 x 4 solved my problem :+1:.

Unfortunately, I am a beginner in this field and I did not understand much from your guidance. Anyway, thank you for guiding me and introducing me to new topics.

I am thankful with your guidance. I rearranged the dimensions of the photo and the problem was solved.