Yura Posted October 31, 2016 Share Posted October 31, 2016 All good day from the start I want to apologize for my English. I need to create a pool and now I'm focused on the problem of when to make the play area. How best to do this? What I found - a rectangular area. I also need to know where this should be done in pixi.js or physical framework (like p2.js or physics.js) Thank you for your reply;) Quote Link to comment Share on other sites More sharing options...
xerver Posted October 31, 2016 Share Posted October 31, 2016 Pixi doesn't have anything to help you with this, it is just for drawing (for the most part). You can do it yourself, or use something like p2.js for a more "accurate" physics feel. Yura 1 Quote Link to comment Share on other sites More sharing options...
Yura Posted October 31, 2016 Author Share Posted October 31, 2016 27 minutes ago, xerver said: Pixi doesn't have anything to help you with this, it is just for drawing (for the most part). You can do it yourself, or use something like p2.js for a more "accurate" physics feel. Unfortunately, I did not find the desired functionality of these libraries. You can not tell me about some api? Thanks for the answer) Quote Link to comment Share on other sites More sharing options...
xerver Posted October 31, 2016 Share Posted October 31, 2016 Not sure what you mean, p2.js is a full physics simulation with everything necessary for a game of pool. What was missing? https://github.com/schteppe/p2.js http://schteppe.github.io/p2.js/demos/restitution.html Yura 1 Quote Link to comment Share on other sites More sharing options...
Yura Posted November 18, 2016 Author Share Posted November 18, 2016 On 10/31/2016 at 8:41 PM, xerver said: Not sure what you mean, p2.js is a full physics simulation with everything necessary for a game of pool. What was missing? https://github.com/schteppe/p2.js http://schteppe.github.io/p2.js/demos/restitution.html Thank you for your response. I have one question: how to use p2.js plane as in billiards (like the camera to turn down) because most demos p2.js made in the form side. Quote Link to comment Share on other sites More sharing options...
xerver Posted November 18, 2016 Share Posted November 18, 2016 There is no orientation, it is 2D. Just make a plane, turn off gravity, and start applying forces. Yura 1 Quote Link to comment Share on other sites More sharing options...
Yura Posted November 18, 2016 Author Share Posted November 18, 2016 16 minutes ago, xerver said: There is no orientation, it is 2D. Just make a plane, turn off gravity, and start applying forces. But the plane must specify some coordinates? For example: planeBody = new p2.Body({ position:[0,-3] }); Quote Link to comment Share on other sites More sharing options...
xerver Posted November 18, 2016 Share Posted November 18, 2016 Sure, what I mean is there is no difference between a square "on the side" and a plane in "top down view" for 2D. Those two shapes are identical. Quote Link to comment Share on other sites More sharing options...
Yura Posted November 18, 2016 Author Share Posted November 18, 2016 55 minutes ago, xerver said: There is no orientation, it is 2D. Just make a plane, turn off gravity, and start applying forces. You do not know the resources at some examples pixi.js + p2.js? Quote Link to comment Share on other sites More sharing options...
xerver Posted November 18, 2016 Share Posted November 18, 2016 http://schteppe.github.io/p2.js/examples/pixijs/box.html https://github.com/schteppe/p2.js/tree/master/examples/pixijs Also phaser uses both pixi and p2. Quote Link to comment Share on other sites More sharing options...
Yura Posted November 18, 2016 Author Share Posted November 18, 2016 12 hours ago, xerver said: http://schteppe.github.io/p2.js/examples/pixijs/box.html https://github.com/schteppe/p2.js/tree/master/examples/pixijs Also phaser uses both pixi and p2. world = new p2.World(); // Add a box boxShape = new p2.Box({ width: 2, height: 1 }); boxBody = new p2.Body({ mass: 1, position:[0, 1], angularVelocity:1 }); // Turn off global gravity world.applyGravity=false; // Keep track of which bodies you want to apply gravity on: var gravityBodies=[boxBody]; // And just before running world.step(), do this: var gravity = p2.vec2.fromValues(0, -110), gravityForce = p2.vec2.create(); for(var i=0; i<gravityBodies.length; i++){ var b = gravityBodies[i]; p2.vec2.scale(gravityForce,gravity,b.mass); // F_gravity = m*g p2.vec2.add(b.force,b.force,gravityForce); // F_body += F_gravity } boxBody.addShape(boxShape); world.addBody(boxBody); // Add a plane planeShape = new p2.Plane(); planeBody = new p2.Body(); planeBody.addShape(planeShape); world.addBody(planeBody); Thank you. You really helped me. If you will have some free time, please tell us why, after the code block, though came across the border When I commented code width the plane, everything looks good. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.