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

Center stage on particular object #2424

Closed
Darker opened this issue Mar 31, 2016 · 3 comments
Closed

Center stage on particular object #2424

Darker opened this issue Mar 31, 2016 · 3 comments

Comments

@Darker
Copy link

Darker commented Mar 31, 2016

In the process of making a 2D game it's typically required that the view is centered on whatever represents the player. At this point, I don't know how to do that apart from manually offsetting all coordinates of all sprites.

How to properly move the stage so that player is always in the center of the canvas view?

@ivanpopelyshev
Copy link
Collaborator

I use standart position/scale/pivot combo.

//(0,0) for us is center of the screen
stage.position.x = renderer.width/2;
stage.position.y = renderer.height/2;
//scale it
stage.scale.x = 2.0;
stage.scale.y = 2.0;
//now specify which point INSIDE stage must be (0,0)
stage.pivot.x = character.position.x;
stage.pivot.y = character.position.y;

In my development version there's secret Camera object, and its possible to make it follow any object even if its inside some containers.

@Darker
Copy link
Author

Darker commented Apr 4, 2016

Thank you very much, it works perfectly! :)

It also answered another question I needed but didn't even ask - how to zoom the stage.

@Darker Darker closed this as completed Apr 4, 2016
@lock
Copy link

lock bot commented Feb 25, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants