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

Resizing world makes bodies moving by themselves #50

Closed
Danetag opened this issue Dec 3, 2014 · 11 comments
Closed

Resizing world makes bodies moving by themselves #50

Danetag opened this issue Dec 3, 2014 · 11 comments

Comments

@Danetag
Copy link

Danetag commented Dec 3, 2014

Hi!

I don't know if I'm doing that right, but I would like to use the engine in fullscreen. So on window resize, I'm adjusting the world bounds:

engine.world.bounds.max.x = window.width;
engine.world.bounds.max.y = window.height;

When I'm doing that, all the none-static bodies are moving by themselves to the right, without any interaction :/

What's happening? Is there any method to resize the world?

Thanks!

@liabru
Copy link
Owner

liabru commented Dec 3, 2014

That code should work, it's the same as I'm doing in DemoMobile.js so take a look there.

I'm not sure what you mean that they move, do you mean they are translated or do you mean they actually gain some velocity?

@Danetag
Copy link
Author

Danetag commented Dec 5, 2014

It seems they actually gain velocity!

@liabru
Copy link
Owner

liabru commented Dec 5, 2014

Hmm that's weird. Can I see a jsfiddle?

@liabru
Copy link
Owner

liabru commented Dec 28, 2014

Did you manage to figure this one out?

@Danetag
Copy link
Author

Danetag commented Dec 28, 2014

Hey!

Not really, had to move to an other project, this issue is still on :/ Thanks tho!

@liabru
Copy link
Owner

liabru commented Jan 1, 2015

I can't reproduce your issue by changing the bounds max as you said in your first post.
Can you provide an example?

@liabru
Copy link
Owner

liabru commented May 24, 2015

I think this will no longer be an issue as of #67 so closing. Please update if this is still a problem.

@liabru liabru closed this as completed May 24, 2015
@vtheviking
Copy link

Hey i noticed that im experiencing the same problem. Im trying to use
var h = window.height;
var w = window.width;
engine.world.bounds.max.x = w;
engine.world.bounds.max.y = h;
function resizeCanvas() {
window.addEventListener('resize', resizeCanvas, false);
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

resizeCanvas();

but it doesn't seem to be resizing my canvas element. Im trying to get the canvas to adjust its height and width according to the size of the viewport or window screen and change as the screen resizes, i looked at issue #67, and i made the post at #118. Im not seeing any results yet, and if you can point me in the right direction for objects sticking to the "ground" or set boundaries like at the website www.berberianmysterytheatre.com you could see the objects settling or sticking to a boundary after about 20seconds or so.

Thanks again btw.

@liabru
Copy link
Owner

liabru commented Jul 20, 2015

Are you using the latest master build? If not then switching to it will resolve this.

@vtheviking
Copy link

I don't think so, ill implement the new build and see how it turns out, and update the issue.
thanks though!!

@jacobclarke92
Copy link

jacobclarke92 commented Feb 6, 2020

I experienced this issue too but on phaser's (currently 3.22.0) implementation of MatterJS.
I worked out it was because I wasn't updating world bounds upon window resize, so at a certain point the right hand bound wall would pass over my character's hitbox and either force them to move left or right depending on which side of the wall they were closer to.

Normally this might be fine / unnoticeable but because I was repositioning the character to the centre of the screen each frame and moving everything else based on that difference from the center point, it meant that my whole world perpetually whizzed by at particular screen aspect ratios.

This might help someone so figured I'd post, no need to re-open.

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

4 participants