SinhNQ Posted July 13, 2017 Share Posted July 13, 2017 Hi all! I'm working on Canvas2D and I have problem with position of Sprite2D. Currently, origin only support for rotation and scale . Default, position coordinate bottom/left corner, I want to position coordinate (0,0) is center of Sprite2D (same as anchor property Sprite of Pixi.js, Phaser.js). How to do this? Thanks for all! Sorry my bad English. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 13, 2017 Share Posted July 13, 2017 Hi @SinhNQ, welcome to the forum. https://www.babylonjs-playground.com/#1KDQTU#22 See line 20. Hope this helps. Be well. SinhNQ 1 Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted July 13, 2017 Author Share Posted July 13, 2017 (edited) Thanks for answer But seem you misunderstand me. As same as rotation, if origin (0.5,0.5) then sprite2D will rotate at the center. I also want to position coordinate system start at the center. You can see: https://www.babylonjs-playground.com/#R3W60Q Uncomment line 24, that is what I want. Thanks so much Edited July 13, 2017 by SinhNQ Wingnut 1 Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted July 13, 2017 Author Share Posted July 13, 2017 (edited) @Wingnut I found an example https://jsfiddle.net/api/mdn/ When I drag slider x , y to 0,0 then anchor of the letter 'F' at the center. How to do this? Edited July 13, 2017 by SinhNQ Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 13, 2017 Share Posted July 13, 2017 I see nothing at that URL. But anyway... I did some playing. https://www.babylonjs-playground.com/#R3W60Q#1 Why line 23 ? I dunno. hehe. But we are rotating around center. Is this what is wanted? Quote Link to comment Share on other sites More sharing options...
SinhNQ Posted July 13, 2017 Author Share Posted July 13, 2017 I'm sorry! https://webglfundamentals.org/webgl/webgl-2d-geometry-matrix-transform-center-f.html Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 13, 2017 Share Posted July 13, 2017 *nod, thx*. Yeah. I'm not sure HOW to hard-set that sprite2D center. Fellow forum helpers... SinhNQ would like the sprite2d to be centered by default... like this. BUT, without needing line 24. Perhaps wrap it within Group2d or Rect2d? Nah, that doesn't sound right. I'll keep thinking, S. Hopefully, somebody has a solution. SinhNQ 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.