Jump to content

base way to integrate box2d into phaser3.


j.c
 Share

Recommended Posts

actually I have done this, but with the unit transformation issue, I need to find a best way to refactor my existing code.

as you know box2d unit is meter, game unit is pixel, so when you create box2d Bodies you need to use a fixed factor you specified for example 100px = 1meter, so they are in the game world is really small for example a basketball is 0.3meter (30cm), the corresponding pixel should be 330px but if you don't scale your game world up it will be displayed as 0.3px , to scale game world bigger is very easy in Phaser3, there are a few ways to do that, like directly set camera.zoom etc.

now another problem comes, I don't need my basketball in the game looks so big, if in pure GL code I can use gluOrtho2D to fix my display proper.

so how can I achieve this in Phaser 3?

 

 

 

 

Link to comment
Share on other sites

@j.c a working example, you may find the answer in the factors inside:

http://lo-th.github.io/crossed/phy_b2d.html

click the github fork me on top to see and clone the whole repository. The content of that particular example on pixi box2d is this one:

https://github.com/lo-th/crossed/blob/gh-pages/phy_b2d.html

It's an old version but check the function update() { ... }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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