I’m in the process of changing all of my “setReferencePoint” functions. I agree that having custom anchor points is more useful, but for now the 9 basic points we had before are satisfactory for me. So I’m changing all of my
obj:setReferencePoint(display.TopLeftReferencePoint)
to
obj.anchorX, obj.anchorY = 0, 0
I’ve made a function where I can provide an object and a string such as “TopLeft” to make the process of switching to anchor points simpler.
function setAnchors(obj, pos) local x, y = 0.5, 0.5 if pos == "TopLeft" then x, y = 0, 0 elseif pos == "Top" then x, y = 0.5, 0 elseif pos == "TopRight" then x, y = 1, 0 elseif pos == "CenterLeft" then x, y = 0, 0.5 elseif pos == "Center" then x, y = 0.5, 0.5 elseif pos == "CenterRight" then x, y = 1, 0.5 elseif pos == "BottomLeft" then x, y = 0, 1 elseif pos == "Bottom" then x, y = 0.5, 1 elseif pos == "BottomRight" then x, y = 1, 1 end obj.anchorX, obj.anchorY = x, y end
setAnchors(myObj, "TopLeft")
What I want to know is, is there a way I could create a function that can be called by all display objects?
That way I could simply redefine setReferencePoint() to perform my function above, and the calling object would be passed in as an argument automatically.
I’m guessing that either it’s not possible, or it’s really simple and I’ve overlooked something.