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
Use of Stage.js #44
Comments
Hi Cristian, Thanks for your suggestion. I'll definitely try that. It would be a lot better for me as I could use the debug/testbed functionality. I came up with something different, but I don't know if it is correct and the most efficient way of achieving what I wanted. The example below is very primitive, is just a rolling ball down the sloped edge. There are still few unknowns for me, like for example the step function - not sure what value should I use for that, I know 1/60 doesn't work well when you have a bouncing ball for example, as I had the impression that the ball never came to rest. Finally, I've got a problem with scaling of my box2d/planck.js bodies vs graphics rendered by the stage.js, this is why I kind of like your approach as I still could have the debug/testbed functionality, currently I didn't manage to figure out how to enable debug/testbed in my simple stage.js example below.
Thanks for your comment once again. |
Here is my recommended approach:
See renderWorld in tesbed. |
I added a stage.js example with planck.js physics. It does not support adding graphics yet, but I will add it soon. |
Thanks Ali, For your both replies. Especially the first one. I indeed took a closer look at the testbed in planck.js, especially the viewer class and then started to look at the breakout code which uses stage-p2.js, where the viewer class is almost identical and that gave me some good idea how to move on. Thanks for the new examples, I'm sure I'll make use of them. Chris |
@blizniak83 Right, breakout/stage-p2.js is a good example. |
Is there any reason why the world in the asteroid example is upside down? I remember when initially using the viewer class from the testbed I had the same problem and I had to use the scale method on the stage object (scale(1,-1)) to get the right orientation. Is this caused because of the way you attache the viewer/Stage.planck? I noticed that after adding some bodies but also after setting the gravity to -10. |
The reason is that physics y-axis is upward, but rendering is downward. Physics engines orientation/scale is usually based on real world physics, but graphic libraries is based on the screen with top-left as the origin. |
undetstood but if I want to render the physics bodies like they behave in the physics world then I have to flip the stage upside down, correct? I think this is what was done in the breakout example. What would be the best method to achieve that in the asteroid example? I managed to achieve that by using world.scale(80, -80), but I know it isn't the best way as it is affecting stage.on() making it no longer responsive to the changes applied to the browser window size. |
I think I just solved my own problem, partially of course, I applied the scale to the stage, this time scale(1,-1), it renders what I want, when looking at the physics bodies, but of course the 'status' element etc. has to be rendered differently. |
Probably you could add the world element (with -y scale) to a new element, for example called gameView, and then add gameView to stage and scale it with window resize. |
Thank you for your suggestion. I tried few things and at one point I thought everything was working as expected but after adding the first texture I noticed that it was upside down. Of course I could use -y scale but there must be a better way. Below is the code extracted from the asteroid example. I know I can flip everything just by -y scaling the stage node. How would you attach the world element to a new element? Do you mean to new node (node = Stage.create())? I'm sure I'm doing something wrong, I tried to -y scale the meta element just to see if this would turn the status text upside down but that didn't work.
|
My last suggestion was not good, now I recall for P2.js viewer I actually multiplied all |
I updated the viewer, please feel free to try it and let me know. |
Another solution is to just setup the game world with y pointing down. |
If shakiba would just listen to what I have to say on my issue. |
@prolightHub what are your thoughts? |
Hi,
I had a chance to play with Planck.js and Stage.js, but separately.
I'm not js guru. In the last few days I decided to use the library without the testbed.
My first choice was to replace it with Stage.js.
I follow box2d manual hello world example, nothing super ambitious.
I have a bouncing ball on a flat surface/edge. Now I want to use Stage.js to render that on the screen.
It seems like all examples are testbed examples. Even though it supposed to be only a case of calling the world.step(timestep) function, I'm still struggling as I assume there will be something similar needed on the Stage.js side.
Would it be possible to post an example that uses Stage.js? Something really simple.
Thank you.
Chris
The text was updated successfully, but these errors were encountered: