Hi, I’m trying to figure out how to display.save things to the documents directory with a POT (power of two) resolution. I’m having trouble understanding the relationship between a display object’s height/width, contentHeight/contentWidth, the screen’s contentHeight/contentWidth, its pixelWidth/pixelHeight, and the size of a saved .png file that I make with display.save.
For example, in the simulator, when I’m using the iPad Air skin, there appears to be a direct relationship (or a very close one) between an object’s .width and .height property and the resolution that they save at. For example, if I have a display object whose .width and .height properties are 657, then it will save to an image whose resolution is also 657. But something goes wrong when I want to save at a different resolution. Let’s say instead I want to save an image which is 1024 x 1024. So I scale the image by 1024/657 (which is 1.5585), then it seems to me that with this increased scale, my saved image should be 1024. But it’s not – it’s 1028! I’m not sure why. Am I missing a variable?
The problem gets bigger when I’m working in different device skins – when the ratio of the screen is much different, on an iPhoneX skin, for example, if the .height and .width properties of that same display object become 643 (not 657), and the saved image size becomes 1029 x 1029, instead of the desired 1024 pixels. So it seems clear it’s not just the width/height properties.
What should I use, then, to save to the right size? Here is the relevant portion of my config.lua:
application = { launchPad = false, content = { width = 320, height = 480, fps = 30, scale = "letterbox", audioPlayFrequency = 44100, antialias = true, imageSuffix = { ["@2x"] = 0.1, }, }, }