Jump to content

Move stage pivot so that element is center


Muhammad Adnan
 Share

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?

Link to comment
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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...