-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Closes #618] Fix Actor anchoring and scaling draw #619
Conversation
There's still some work left for children/sprites. |
I think I've figured this out, let me explain. The problem: Sprite centering only worked when the sprites were the exact dimensions of the actors bounding box. This is because the actors anchor is set to the middle (.5, .5) which is a good default I believe, so the default drawing are shifted actor.width * .5 and actor.height * .5 and because sprites draw from top left by default this works great. However, if these dimensions don't line up exactly, either the sprite is smaller or larger than the bounding box of the actor, the offsets are not correct. The solution: If we want drawings to be centered, we need to account for this by developing an additional offset from the actor anchor itself. The formula below I believe accomplishes this in all cases. The idea is that we want the sprite offset (the relative position in the drawing for example (.5, .5) is the center) to be translated to the center of the actor. |
Having a spriteOffset of (.5, .5) has a natural consequence of centering sprite scaling around the center of the actor, so if you want a top left to be the center of scaling you must also set spriteOffset to (0, 0) as seen here: This begs the question, should spriteOffset and anchor always be the same thing? |
@kamranayub spotted an issue in the coordinate test, child actors were not centering on the grid based on their anchors The fix in 62ff021 was to wrap the anchor translations in a |
@excaliburjs/core-contributers if we are in agreement this sucker can be merged! |
I'm so ready to merge this, let's do it! On Thu, Aug 18, 2016 at 12:30 PM Erik Onarheim [email protected]
|
Closes #618
I added a new visual test for testing anchoring with
fillRect
and Sprite drawing. It's a mess in the current version, as you can see:The anchor is being double-scaled and sprite drawing is super weird even with
setCenterDrawing
to false for everything except the center test.After making some changes to the draw call logic, I believe I've fixed it properly:
I removed all the center drawing cruft, since now it will properly draw anchored correctly.
Proposed Changes:
Actor.draw
call logic to avoid double scalingsetCenterDrawing
logic