Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
box2d: support custom stage size (#1224)
This PR makes the Box2D extension create boundaries around the stage size when the stage size is (re)set to boxed, instead of using set sizes and positions for a 480 pixel by 360 pixel stage. For the floor stage type, it scales the floor width, since the floor was originally always 5000 units in width which could make stages 5000+ pixels in width not have a full-width floor. It also adds comments where the stage type is set to explain the code and numbers. I think it could be useful since it took me many moments to figure out what the magic numbers meant. **New Constants** ```patch - bodyDef.position.Set(0, 1000 / zoom); + bodyDef.position.Set(0, (stageBounds.top + 820) / zoom); ... - fixDef.shape.SetAsBox(10 / zoom, 800 / zoom); + fixDef.shape.SetAsBox(10 / zoom, (stageHeight + 820) / zoom); ``` Originally the ceiling was positioned at 1000 units, so to get 820 I subtracted 180 (default top bound) from 1000. ```patch + const floorY = (stageBounds.bottom - 100) / zoom; ``` Originally the floor boxes were positioned at `-280 / zoom`. I think this is from a y of -180 (bottom stage bound) with 100 units subtracted because the boxes have a height of 100. ```patch - fixDef.shape.SetAsBox(5000 / zoom, 100 / zoom); + fixDef.shape.SetAsBox((stageWidth + 4520) / zoom, 100 / zoom); ``` I just subtracted 480 from 5000 since the stage is 480 pixels wide by default and the boxes were originally 5000 units wide. ___ This PR resolves suggestion 1 from #236. --------- Co-authored-by: Muffin <[email protected]>
- Loading branch information