SkyzohKey Posted February 5, 2015 Share Posted February 5, 2015 Hello ! How am I supposed to set the anchor point for a game.Graphics object ? Here's my code : this.sprite = new game.Graphics();this.sprite.beginFill(this.border);this.sprite.drawRect(0, 0, this.size.width, this.size.height);this.sprite.beginFill(this.background);this.sprite.drawRect(0 + this.borderSize, 0 + this.borderSize, this.size.width - this.borderSize * 2, this.size.height - this.borderSize * 2);this.sprite.position.set(this.position.x, this.position.y);// this.sprite.anchor.set(0.5, 0.5) is not working :/Thanks a lot for your futures answer ! EDIT : SOLVED MY PROBLEM BY DOING THIS :this.sprite.drawRect((-this.size.width / 2), (-this.size.height / 2), this.size.width, this.size.height);this.sprite.position.set(this.position.x - (-this.size.width / 2), this.position.y - (-this.size.height / 2));Thanks to enpu to make me in the right way ^^ Quote Link to comment Share on other sites More sharing options...
enpu Posted February 5, 2015 Share Posted February 5, 2015 There is no anchor point in Graphics. Try pivot.set(0.5, 0.5); or draw your rect into center, like drawRect(-50, -50, 100, 100); Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted February 5, 2015 Author Share Posted February 5, 2015 Hey enpu, thanks for the great game engine you coded ! this.sprite.pivot.set(0.5, 0.5) is not working. Then my code is for the Button plugin I'm developping, so the coordinates could be different on each call :/(You can see the source-code on my GitHub : https://github.com/FishTFM/PandaJS-Button-Plugin) Thanks for ur' help anyway Quote Link to comment Share on other sites More sharing options...
enpu Posted February 5, 2015 Share Posted February 5, 2015 Try something like this:this.sprite.drawRect(-this.size.width / 2, -this.size.height / 2, this.size.width, this.size.height); SkyzohKey 1 Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted February 6, 2015 Author Share Posted February 6, 2015 Hmm, this is not working :/I got the scale effect direction reversed but not "anchor point" set to the center of the graphics :/ Is there a way to perfom a graphics to sprite conversion by the code ? EDIT: Solved, 1st post updated ^^ Quote Link to comment Share on other sites More sharing options...
enpu Posted February 6, 2015 Share Posted February 6, 2015 Great that you got it working! Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted February 6, 2015 Author Share Posted February 6, 2015 Yep, don't know how to make the post solved but Thanks a lot The login button is now pefect ! SkyzohKey 1 Quote Link to comment Share on other sites More sharing options...
enpu Posted February 6, 2015 Share Posted February 6, 2015 Nice! Quote Link to comment Share on other sites More sharing options...
SkyzohKey Posted February 6, 2015 Author Share Posted February 6, 2015 Nice! I used some resources from your endlessrunner but will change them as soon as my graphic maker be at his home ^^ Quote Link to comment Share on other sites More sharing options...
enpu Posted February 6, 2015 Share Posted February 6, 2015 That's totally fine! 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.