@Sergey
Thanks for looking into it. I am sorry to hear that the newRect + imageSheetFill idea didn’t pan out.
I was thinking that it could be handled a bit easier, using math instead of trying to recreate the actual transparent pixels of the original untrimmed image. Similar to what Rob mentioned in a reply above. (Also that’s why I used “untrimmed” in quotes in my feedback request
).
Anyway, this is what I had in mind and I made a simple function to illustrate the idea:
local sheetInfo = require("images.conveyor\_trimmed") local conveyorSheet = graphics.newImageSheet( "images/conveyor\_trimmed.png", sheetInfo:getSheet() ) local function getUntrimmedImage(parentGroup, sheet, frame, targetWidth, targetHeight) local sheetFrame = sheetInfo.sheet.frames[frame] local sourceWidth, sourceHeight = sheetFrame.sourceWidth, sheetFrame.sourceHeight local actualWidth, actualHeight = sheetFrame.width, sheetFrame.height local image = display.newImageRect(parentGroup, sheet, frame, actualWidth, actualHeight) --Check if the frame is actually trimmed if sourceWidth and sourceHeight and (sourceWidth ~= actualWidth or sourceHeight ~= actualHeight) then local widthRatio = actualWidth / sourceWidth local heightRatio = actualHeight / sourceHeight local scaleX = targetWidth / actualWidth local scaleY = targetHeight / actualHeight image.width = actualWidth \* scaleX \* widthRatio image.height = actualHeight \* scaleY \* heightRatio end return image end
Ideally this would be incorporated into the display.newImageRect() function and it would be done behind the scenes by Corona. Corona already detects if there is a sourceX and Y offset and automatically applies it, so I’m assuming there’s a way to do the same with detecting when the images have been trimmed by seeing if sheetInfo contains sourceWidth and height attributes.
This function works pretty well for keeping trimmed images proportional when using an arbitrary width and height, but there is an issue with sourceX and Y offsets. Either they are not being respected or I don’t understand how they are supposed to work (or TexturePacker is doing something weird), but my trimmed images are not aligned properly when placed in a grid. Here is a screenshot to illustrate what I mean. The upper left conveyor uses my untrim function, the lower right uses the actual untrimmed image sheet.

Also, I had to update sheetInfo.lua to rearrange the frames because TexturePacker likes to put frame 10 after frame 1. If you want the updated sheet I can PM it to you.