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

Restrict viewport to the world borders when follows object #47

Closed
CurlyBraceTT opened this issue Mar 27, 2018 · 2 comments
Closed

Restrict viewport to the world borders when follows object #47

CurlyBraceTT opened this issue Mar 27, 2018 · 2 comments

Comments

@CurlyBraceTT
Copy link

When using follow method - viewport shows areas beyond world box. I restrict viewport position by next lines inside the update method of the follow plugin:

this.parent.x = Math.min(this.parent.x, 0);
this.parent.y = Math.min(this.parent.y, 0);
this.parent.x = Math.max(this.parent.x, this.parent.screenWidth - this.parent.worldWidth);
this.parent.y = Math.max(this.parent.y, this.parent.screenHeight - this.parent.worldHeight);

Is there a better way to do this and maybe this should be done on a higher level?

@davidfig
Copy link
Owner

Did you try viewport.clamp()? That keeps the camera from moving beyond the borders and works with follow.

@CurlyBraceTT
Copy link
Author

clamp solved it, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants