I am beginning to get frustrated by certain implementations for graphics 2, and I’d be curious to know why some things are how they are.
One thing that has caught my attention is how you now specify things from their center points (IE top and left are gone, replaced by X and Y which are now the mid-points of the object).
The most obvious example is newRect().
I have mentioned in the past in the widgets forum my dislike of using the center of objects as reference points (for example you create a rectangle 25 by 25 pixels - the middle is now 12.5, 12.5 pixels - no guarantee of how the graphics engine will round this up or down, especially when you factor in content scaling - it has been this that is the cause of a lot of the widgets graphical bugs because the code uses center points everywhere and the maths just doesn’t always work).
I assume this decision was to make pretty much all object definitions identical in practice (for example, images have always had their reg point created at the center).
Now part of the problem is of course, I’m testing by updating an old project - things would likely be different when I am comfortable with the new way
It appears I have a few choices when creating a rectangle now:
local rect = display.newRect( 0, 0, width, height )
rect.x = x + math.floor( width / 2 )
rect.y = y + math.floor( width / 2 )
- I *think* this would work, not sure!
local rect = display.newRect( 0, 0, width, height )
rect.anchorX = 0
rect.anchorY = 0
rect.x = x
rect.y = y
2a) *would* this work?
local rect = display.newRect( x, y, width, height )
rect.anchorX = 0
rect.anchorY = 0
local rect = display.newRect( x + math.floor( width / 2 ), y + math.floor( width / 2 ), width, height )
instead of:
local rect = display.newRect( x, y, width, height )