Spritesheet can't handle single row sheets > 640 pixels wide

5 replies [Last post]
MarkHenryC
User offline. Last seen 5 weeks 1 day ago. Offline
Joined: 11 Nov 2009

Unfortunately I think I've found another problem with spritesheets. If, for example, you wish to have a spritesheet 1 frame high and n frames across, you'll get assertions if the source image file is > 630 width. This may be related to bug 1808 I reported.

The assertion spuriously reports that frames don't fit in sheet. The first error is for the height, even though this hasn't changed. If you subtract 1 from this it gets through but still fails on the width test. For example, it reports an error for an image height of 40 pixels with a frame height of 40 when the image width is > 640. If you subtract 1 it's OK. So it seems that Corona is shrinking the image dimensions internally.

The test code I've supplied shows this. Files 320x40 and 640x40 are OK but 960x40 and 1040x40 are not.

Project file here

Replies

MarkHenryC
User offline. Last seen 5 weeks 1 day ago. Offline
Joined: 11 Nov 2009

This bug is still in the new beta game SDK. I guess it's not considered important, but it may come back to bite sometime, as it suggests there's some parsing error in the image load code.

Eric
User offline. Last seen 1 year 9 weeks ago. Offline
Joined: 23 Jun 2009

In your project, the file 24x1.png is actually 640 wide, not 960. Updating it to 960 (by cropping the 1040 version) works.

In Corona right now 1024 is the max texture size, so the 1040 version doesn't work. 1024 is the limit on iPhone 2G and 3G. Newer devices support larger textures, and I've added a case to ask the device for the max texture size. However, for compatibility we recommend staying with 1024.

MarkHenryC
User offline. Last seen 5 weeks 1 day ago. Offline
Joined: 11 Nov 2009

Thanks for your response, Eric. You are right of course. 1040 was a mistake. Was meant to be 1024. And the other reported assertion was, in fact, correct because one of the loads did not result in integer frame sizes. This leads back to bug report 1808 as stated in the original post:

Running this script:

local images = { 320, 640, 960, 1024 }
 
for i =1, #images do
        local iName = images[i] .. "x40.png"
        local img = display.newImage(iName)
        print("Image " .. iName .. " width: " .. img.width .. ", height: " .. img.height)
end

Gives this output (I made sure the file sizes were correct this time):

Image 320x40.png width: 320, height: 40
Image 640x40.png width: 512, height: 32
Image 960x40.png width: 512, height: 21
Image 1024x40.png width: 512, height: 20

For building Lua libraries and utils for Corona, it would be real handy to check image file dimensions without having to manually parse them.

Eric
User offline. Last seen 1 year 9 weeks ago. Offline
Joined: 23 Jun 2009

If you don't want images to autoscale to the display, use the isFullResolution flag.

Sprite sheets are not handled in the same way as images. Autoscaling is always off. There is a max size enforced, which is currently 1024. This isn't accurate for some devices and I opened a case to handle this (especially on iPad). However for compatibility, you should stick with 1024.

MarkHenryC
User offline. Last seen 5 weeks 1 day ago. Offline
Joined: 11 Nov 2009

I'm not sure why, for example, an image 640x40 would "autoscale" to 512x32. Is this a quirk of the simulator, in that it thinks the iPhone sim display is 512 wide?

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.