Muhammad Adnan

Move stage pivot so that element is center

Recommended Posts

Hey everyone,

I want to center an element (in this case a graphics element) in the center of the screen. 

https://jsfiddle.net/user/adnanchang/fiddles/

As you can see from my code, I am changing the position of the graphics and bringing it to the center of the screen. I don't want that. I want to actually move the pivot/position of the stage in such a manner that the graphics then looks like it is to the center of the screen. Also, would it be possible to save the original position of the stage?

Share this post


Link to post
Share on other sites

Everything is possible, its just you need to wait for another helper, other than me :) 

 I just dont want to give you more code unless you figure out some stuff for yourself, from my point of view, you already have everything to figure out the solution.

Share this post


Link to post
Share on other sites

You could just say stage.x = renderer.width/2 and stage.y = renderer.height/2. Then your stage is in center and everything under it is rendered in relation to the stage.

Though I would suggest keeping the stage in 0,0 and create another container which you move to center and have graphics added under that. Makes it a lot easier to implent overlay ui for example when you dont have to do inverse calculations to get items where you want.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.