Skip to content
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

Rewrote text alignment method to work with sprites #18

Closed
wants to merge 8 commits into from

Conversation

NathanFlurry
Copy link

I rewrote the text alignment code to reposition the text in CanvasText instead of moving the sprite or mesh object itself. With the current method of text alignment, sprites appear to behave oddly when rotating. This is because sprites always pivot around the origin of the object, so moving the sprite's position itself based on the text size just moves the entire sprite and does not change the pivot point. However, by doing the text alignment in the canvas itself, the sprite's pivot point will remain the same and the text moves around the pivot point appropriately.

The only downside to using this method is that the canvas size will be about twice as big as required to render the text, since there needs to be a lot of empty space for left and right alignment.

…e children themselves

This is because positioning the `Sprite` in `SpriteText2D` does not work properly, since the pivot of the sprite is always the center no matter what
Ran prepublish
@endel
Copy link
Member

endel commented Jun 15, 2017

Hey @NathanFlurry,

Thanks for your pull-request. I really wouldn't like to increase the texture size even more though. :(

One major concern of using this library is performance. Each text you create with this library generates a new texture, which will increase your draw calls. It would be awesome to have a single texture in which all texts could share, having just one draw call. (#7) - and it would be better to have it as small as possible.

I'll ask you to kindly to remove the lib/*.js and lib/*.d.ts files. (sorry, the .gitignore should be taking care of this already)

I'll find some time to review during the weekend.
Thanks!

@NathanFlurry
Copy link
Author

I fixed the .gitignore and added the option to choose the alignment. The MeshText2D defaults to child alignment (the old alignment) and the sprite defaults to texture alignment. This is configurable using TextOptions.alignmentMethod if the developer wants to switch.

Thanks!

@NathanFlurry
Copy link
Author

@endel Did you get a chance to look at this PR? Thanks!

@endel
Copy link
Member

endel commented Feb 5, 2019

closing this since #29 has made into master!

@endel endel closed this Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants