Stage doesn't get the correct w/h
See original GitHub issueHello @kenwheeler,
First of all, such a great wrapper around matter-js, I didn’t know it before and I found it very useful. Thanks 👍
If I have a basic structure like this:
<Loop>
<Stage width={1024} height={576}>
<World>
<Body args={[20, 50, 100]}>
<Sprite
repeat
src='assets/megaman.png'
ticksPerFrame={1}
scale={1}
steps={[1, 2, 3, 4]}
/>
</Body>
</World>
</Stage>
</Loop>
It renders like that:
<div data-reactroot="" data-radium="true" style="height: 100%; width: 100%;">
<div style="height: 100%; width: 100%;">
<div style="height: 100%; width: 100%; position: relative;">
<div style="height: 0px; width: 0px; position: absolute; overflow: hidden; transform: translate(398px, 0px);">
<div style="position: absolute; top: 0px; left: 0px; height: 100%; width: 100%;">
<div style="height: 64px; width: 64px; overflow: hidden; position: relative; transform: scale(1); transform-origin: left top 0px; image-rendering: pixelated;">
<img src="assets/megaman.png" style="position: absolute; transform: translate(-384px, 0px);" />
</div>
</div>
</div>
</div>
</div>
</div>
Problem
The problem that I was running with this is that <Stage />
creates a Container and an extra element as I can see it here, and forces the size of the container being full screen, but the child to be absolute and defined by getScale
method.
Work-arround
So I need to reset the position of the innerElement adding style={{ position: 'static' }}
into <Stage />
for not be able to overflow
with a non-sized div inside.
Posible explaination?
I’m thinking that the “problem” here is that I’m trying to render a Sprite with a Body on top, so they don’t have the dimensions yet, so the Stage can’t calculate the space correctly?
I couldn’t find a proper description about <Stage />
in the docs, could be worth it explaining it? In the case that I’m right.
I would love to help to improve the documentation and try to contribute to this project and see how perform with HTML 2D Games.
Thanks 😄
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
i check parent dimensions instead of window in case people want to embed in an existing page.
Totally my mistake! Sorry for open this.