Display Group scale not reflected in width/height

This could potentially break any code relying on group.width and group.height:

1
2
3
4
5
6
7
local test = display.newGroup(display.newImage("myImage.png")) -- myImage: width: 256, height: 256
 
test.xScale = 0.5 -- new dimensions for group should be 128, 128
                
print("Width:",test.width,"Height:",test.height) -- prints 256, 256
 
-- note: same result if using test:scale(0.5,0.5)

Could not edit post, just forgot to scale Y:

1
2
3
4
5
6
7
8
local test = display.newGroup(display.newImage("myImage.png")) -- myImage: width: 256, height: 256
 
test.xScale = 0.5 -- new dimensions for group should be 128, 128
test.yScale = 0.5
                
print("Width:",test.width,"Height:",test.height) -- prints 256, 256
 
-- note: same result if using test:scale(0.5,0.5)

I guess the underlying image remains the same size it's just drawn scaled. The easy way to fix this is simply calculate the scaled size and use that.

Yes, but it's utterly wrong.
If you scale a group you should get the group's bounding box dimensions in the width/height members of the group.
So, if the image was actually scaled by the group, its bounding box should be re-computed...and the group should hold the new values.

This is just a plain bug. I will test previous versions... but I guess it was actually working.

Also, you cannot simply hot-fix this in your Lua code.
Say you have all your group objects scaled with the xScale and yScale property... rather than the group:scale() func... then you cannot simply replace a single function. You'd need to rework your thousands-of-lines code! Not feasible.

EDIT:

Also, I'd expect display objects in hierarchy to reflect group scaling, while it's not:

1
2
3
4
5
6
7
local test = display.newGroup(display.newImage("myImage.png")) -- myImage: width: 256, height: 256
 
test.xScale = 0.5 -- new dimensions for group should be 128, 128
test.yScale = 0.5
                
print("Width:",test.width,"Height:",test.height) -- prints 256, 256
print("Image Width:",test[1].width,"Image Height:",test[1].height) -- still prints 256, 256

Not sure if you solved this.

Have you tried your_display_group.height vs your_display_group.contentHeight

I don't think these resolve to the same thing.

Good Luck

This bug also affects the calculation of xReference and yReference, since scaling isn't taken into account for the correct width and height. That means the object will be placed in the wrong position after setting the reference point if the object is scaled.

I'm doing stuff like scaling display groups during transitions, and this bug has made it troublesome since I do layout with the top left as the reference point but scale from the center. It means I have to do a lot more bookkeeping to make sure things are in order.

Is there a solution to this? I'm having a similar issue - where positioning is being messed up as I have a group that is scaled. I can try to do a reposition based off my scaling, but thats a terrible and inefficient way to solve this.

views:1897 update:2012/2/10 9:26:24
corona forums © 2003-2011