This is my first time doing anything with the Graphics Engine 2.0, and having trouble figuring out how to do something I would think would be simple.
I am creating some panels dynamically (doing math on the contentWidth and contentHeight to fit things on all screens) using display.newRect and want to fill them with an image.
Here is the code I am using:
local buttonWidth = [sizing code] local buttonheight = [sizing code] local filenum = math.random( 1,4 ) myPanel[i] = display.newRect( 0, 0, buttonWidth, buttonHeight ) myPanel[i].fill = { type = "image", filename = category.pack[i].filename .. "\_0" .. filenum .. ".jpg" } local scaleFactorY = myPanel[i].width / myPanel[i].height myPanel[i].fill.scaleX = 1 myPanel[i].fill.scaleY = scaleFactorY
The buttonWidth and buttonHeight values change depending on the device, since the contentWidth and contentHeight change based on the universal config.lua that Rob had outlined. (I am using the 1200x800 aspect ratio.)
The buttonWidth values might be 465, 505, 548, or 575 (in my testing in the Simulator).
The buttonHeight values might be 124, 126, or 145 (in my testing in the Simulator).
The fill images are 512px x 256px.
The issue that is happening is that the images are being shrunk to fit the width of the panel. They do not appear to be shrunk vertically, but are correctly “cut.” The problem with this is that the fill images are now the wrong ratio. For example, in one image, there are a bunch of circles. But when viewed in the panel, they are squeezed so they look more like vertical ovals.
is there a way to keep the fills the correct ratio? So that if it does stretch to fit the width (which is fine to cover the issue of the panels being both smaller and larger than the fill image) that it adjusts the height accordingly so the fill doesn’t look skewed?