Search the Community

Showing results for tags 'box2D'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Platform
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 107 results

  1. I am using Box2D physics engine with PIXI.js as the renderer. But I have trouble using it correctly. Box2D is based in MKS(Meters, Kilograms and seconds) But Pixi.js renders everything in pixel. So I need to convert from MKS to pixel when I render sprites/movements. I don't know how to do this properly. I have seen some examples saying I just need to convert the positions using a scale factor in PIXI.js (see this But someone also recommend me to just use stage.scale so that everything in the stage will scale to the particular ratio I choose at the beginning. Anyone has similar experience before? How to render Box2D-based sprites nicely using PIXI.js?
  2. Hello! I'm new to Phaser and Box2D, but I've looked through as many posts as I could find on scaling box2d and am still struggling to get it working well. I'm trying to scale a bunch of sprites, and on each scale step increase the worldsize as well so that I can reset box2d world bounds. I've gotten the world scaling and the sprites scaling, but the physics bodies stay behind. It looks like this: the sprites are beyond the bounds of the world and they are offset from their box2d bodies. Here's what I've tried - using body.setRectangle() to scale the Box2D rectangle as well. I've also noticed that the sprites are scaling faster than the world and are leaving the world bounds. I've been banging my head against the wall for a while and was hoping someone had some wisdom to share. if (this.cursors.up.isDown) { // An internal function that I use to track world scale. This is working fine this.scaleWorld(1); // Scale all the bodies in the world inside a group called stageGroup this.stageGroup.scale.set(this.worldScale); // Set the world scale & reset bounds;, 0, this.worldSize.width * this.worldScale, this.worldSize.height * this.worldScale); // Reset box2d world bounds; // For all sprites in the sprite group, scale them this.stageGroup.children.forEach(child => { // scale x and y child.position.x = child.position.x * this.worldScale; child.position.y = child.position.y * this.worldScale; // This is what I've tried but it's not working child.body.setRectangle(child.initialSize* this.worldScale, child.initialSize * this.worldScale, 0, 0, 0); }); } Thanks!!
  3. Trying to convert my project over to Box2d in Phaser and having trouble... Can someone please tell me what I'm doing wrong here? Attached is the example file for World Bounds, I have made some small changes to incorporate collision categories and masks. Everything is working as expected except for the world boundaries. I have been over the docs many times and I think I am doing this as described. Notice how all the collisions are working except for world bounds. TIA world boundstest.html
  4. I have the Box2d plugin, but game.physics.box2d doesn't have autocomplete when I type "game.physics.box2d" in Visual Studio. In phaser.d.ts I see: arcade: Phaser.Physics.Arcade; config: any; game: Phaser.Game; ninja: Phaser.Physics.Ninja; p2: Phaser.Physics.P2; box2d: any; I think it Might be that it thinks game.physics.box2d is any instead of box2d class. How do I get autocomplete?
  5. On certain computers, ones that wouldn't seem like they should lag, movement in my game is slow. When using `game.time.desiredFps = 30;` it also happens. My question is, how can I drop frames instead of making players swim through mud? Instead of looking ugly, it becomes unplayable. I tested this for p2, it also happens with that physics engine.
  6. The_dude8080


    If I have a custom-player-made drawn image in phaser and I want to make a phyisics body out of it should I use Box2d to set its P2 phyisics body?
  7. I was trying to change the mass of a Box2d body in a PostsolveCollisionCallback, but it was not working as I intended. I checked the behavior in a debugger, and I found out that any of properties of Box2d body (e.g. mass, velocity) could not be changed inside a callback function. I guess this is because those parameters are necessary for some physical calculation, but I would like to know if the is any workaround for this. For now I just created a time event to modify the parameters. I went through the documentation but nothing was found. Shouldn't this be mentioned somewhere?
  8. I have this error : Uncaught TypeError: c.Physics.Box2D is not a constructor Here is the code
  9. Hey My question is pretty straigh forward, is there any alternative to PhysicsEditor, that is at least Free if not OpenSource. Thanks in advance!
  10. I'm using the Box2D plugin and haven't been able to figure out how to remove / destroy joints. Anyone know how to do this?
  11. LATEST UPDATE Hi thanks for looking, but I have figured out my issue since posting this question. Here is a codepen with Box2d Phaser physics moving the bottom sprite with a sprite resting on top , and having the top sprite's physics respond - even after it has been inactive or at rest: --------------------------------- New to Phaser JS and trying to build a "simple" game; If you imagine the game brick breaker - just the base and the ball. I want to be able to move the base up and have the ball still sitting on the base. I also want to be able to tilt the base and have the ball "roll" down depending on which side is tilted. Update 2 Here is a codepen of my Box2d Phaser attempt which comes closest to what I'm trying to achieve. If you use the arrow keys immediately to move the base up,down,left, right (while coliding with the box) then physics work as expected. If you wait a few seconds after the box rests on the base, moving the base has no effect on the box; I would like the box to be effected by the base even after the initial wait: Update 1 Using Phaser's default Arcade Physics, I am now able to get the up movement of the base to keep the ball sitting on-top (although there are some brief overlap's that I'd like to keep from happening and not sure how to prevent that at the moment?); I was not able to allow the ball to "roll" down either side while tilting the base. It seems that even though the base is being rotated that the collision area is not being moved and the ball does not know that it needs to "roll" down. Here is an example phaser sanbox with debugging information (move left or right to see the base rotate):
  12. Hullo! Newbie to phaser - please be gentle I've been play with the body-debug-draw ( ) example. The goal is to make a block which is controlled by the user and as such has zero gravity, with other blocks falling on it. I can't figure out how to set gravity for the one item to zero. If I make the object no longer static, it drops off the screen. If I keep it static, I can't move it with the mouse or keys. Suggestions welcome! Edit: Never mind. Silly error on my part. Sorry for the noise
  13. Hello, I'm trying to reuse a tween to simulate resource gathering and delivery between 2 locations. I was able to successfully accomplish that by chaining tweens but I now want to just reuse 1 tween instead of 4. I modified the tween reuse example and wrapped all the tween function into one 1 (tweenAll) and I call it after everything is setup. Now the problem is that the blockSprite is supposed to drop to the beginning of the platform and then go back and forth on the platform, but instead, it goes back to its initial position ( up in the air) at random moments of the tweening. bellow is what the code looks like applied to body-debug-draw var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); function preload() { game.load.image('platform', 'assets/sprites/platform.png'); game.load.image('block', 'assets/sprites/block.png'); } var platformSprite; var blockSprite; var tween; function create() { game.stage.backgroundColor = '#124184'; // Enable Box2D physics game.physics.startSystem(Phaser.Physics.BOX2D); game.physics.box2d.gravity.y = 500; // Static platform platformSprite = game.add.sprite(400, 550, 'platform'); game.physics.box2d.enable(platformSprite); platformSprite.body.static = true; // Dynamic box blockSprite = game.add.sprite(400, 200, 'block'); game.physics.box2d.enable(blockSprite); blockSprite.body.angle = 30; blockSprite.body.kinematic = true tween = game.add.tween(blockSprite.body) tweenAll() } function render() { // Default color is white game.debug.body(platformSprite); // Make falling block more red depending on vertical speed var red = blockSprite.body.velocity.y * 0.5; red = Math.min(Math.max(red, 0), 255); var red = Math.floor(red); var blue = 255 - red; game.debug.body(blockSprite, 'rgb('+red+',0,'+blue+')'); } function tweenAll() { function tween1() { { rotation: 0.5 }, 500, Phaser.Easing.Bounce.Out, true); tween.onComplete.addOnce(tween2, this); } function tween2() { { x: 200, y: platformSprite.y}, 1000, Phaser.Easing.Bounce.Out, true); tween.onComplete.addOnce(tween3, this); } function tween3() { { rotation: -1 }, 500, Phaser.Easing.Bounce.Out, true); tween.onComplete.addOnce(tween4, this); } function tween4() { { x: 600, y: platformSprite.y}, 1000, Phaser.Easing.Bounce.Out, true); tween.onComplete.addOnce(tween1, this); } tween1() } can anyone tell me why is this happening ?
  14. Hello, I'm having some issues with the sprite and physic body being at two different locations, I would like to have them staying together. I used this Phaser example , then added a camera follow and set the bound of the camera to null (for an infinite world). can anyone enlight me as to why this is happening and how to fix that? Thanks var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render }); function preload() { game.load.image('platform', 'assets/sprites/platform.png'); game.load.image('block', 'assets/sprites/block.png'); } var platformSprite; var blockSprite; function create() { game.stage.backgroundColor = '#124184'; // Enable Box2D physics game.physics.startSystem(Phaser.Physics.BOX2D); game.physics.box2d.gravity.y = 500; // Static platform platformSprite = game.add.sprite(400, 550, 'platform'); game.physics.box2d.enable(platformSprite); platformSprite.body.static = true; // Dynamic box blockSprite = game.add.sprite(400, 200, 'block'); game.physics.box2d.enable(blockSprite); blockSprite.body.angle = 30; blockSprite.body.kinetic = true; game.input.onDown.add(mouseDragStart, this); game.input.addMoveCallback(mouseDragMove, this); game.input.onUp.add(mouseDragEnd, this); = null } function render() { // Default color is white game.debug.body(platformSprite); game.debug.body(platformSprite.body); game.debug.body(blockSprite, 'rgb('+222+',0,'+222+')'); game.debug.cameraInfo(, 500, 32); game.debug.spriteInfo(blockSprite, 32, 32); game.debug.bodyInfo(blockSprite, 32, 132); game.debug.pointer(game.input.mousePointer) game.debug.text("" + 'offset sprite to physic body: '+ blockSprite.body.offset, 2, 14, "#00ff00"); } function mouseDragStart() { game.physics.box2d.mouseDragStart(game.input.mousePointer); } function mouseDragMove() { game.physics.box2d.mouseDragMove(game.input.mousePointer); } function mouseDragEnd() { game.physics.box2d.mouseDragEnd(); }
  15. Hello, I have been trying to use the build in tweening from phaser with a box2d Sprite but didn't have much luck with it. I used this box2d example , turned off gravity and added the tween line. blockSprite = game.add.sprite(400, 200, 'block'); game.physics.box2d.enable(blockSprite); blockSprite.body.angle = 30; game.add.tween(blockSprite).from( { y: -200 }, 2000, Phaser.Easing.Bounce.Out, true); Can anyone tell me what I'm doing wrong here ? Thanks.
  16. by using this example how to stop box2d object from moving after mouseDragEnd i try item.body.x= 100; item.body.y= 200; item.body.mass= 0; item.static = false; item.velocity = 0; but not work
  17. I think groups are not really possible with Box2D based on a post by Rich some where. Instead, I have made some text follow the player by setting it's x and y relative to the player's positions. It's look alright but has a floating appearance like the body moves away faster some of the time. Is there a way to get multiple sprite attached to a body without any floating?
  18. I read another topic that talked about physics hacks to make a platform game work correctly. Someone talked about slowing down movement when near a wall to prevent sticking to walls. I tried this and couldn't get a good result. What is the best way to prevent sticking to walls? The problem seems more about velocity than friction. Though, I'm not exactly sure.
  19. Hi, I'm looking for some advice. I've been trying to create a snowboarding game. I want it to make use of a physics engine so that I can get realistic reactions to the landscape like in FreeRiderHD. So far I have developed a character in box2djs and rigged him together with joints and if I drop him on a slope he goes down it pretty nicely and reacts to bumps as I want... but i cant find any way of actually controlling the character, ie letting the user lean him backwards or forwards and speed up / slow down. So I started looking at Phaser and P2 physics and tried to make a mock version in there. But I can't find any tutorials / advice on rigging a character in there. Is it only for spritesheet characters? Or can you create a character that is a group of physical objects connected by joints? So I'm looking for advice on which is the best way to go to create my snowboarding game and if anyone can anyone suggest a tutorial / code I can go through to learn about either creating a rigged character in phaser OR controlling a character in Box2D. Thanks!
  20. I have been working with Phaser for about 6 months now, and have recently purchased the Box2D plugin, and for the most part its great, although I am having a few basic problems with spawning the sprite with an appropriately sized body, then applying a continuous velocity. Below is the offending function. First a sprite is spawned from a loaded atlas (the zombie), but unfortunately the sprite is way too big (or my game is too small, one of them) and needs to be scaled down to a 1/4 of its original size. I found a question elsewhere on here where someone (it may have even been Rich) gave an answer to define the body separately, then reattach it to the sprite and the sprite to it. This appears to work fine-ish, giving me a body that is registered as the sprite's and collides properly etc etc. On spawn the zombie plays an anim of pulling itself out of the ground (the spawn anim), and then when that is completed it should play the walk animation, then actually move. The commented section within the OnComplete callback shows all of the different methods of getting something to move in Box2D the internet can give me, but none of them work. function spawnZombie(x, y){ var zombie = zombies.create(x, y, 'zombie'); zombie.anchor.setTo(0.5, 0.5); zombie.scale.setTo(0.25, 0.25); var zomBody = new Phaser.Physics.Box2D.Body(, null, x, y, 0.5); zomBody.setRectangle(30, 50, 0, 0, 0); zombie.animations.add('spawn', Phaser.Animation.generateFrameNames('appear/appear_', 1, 11, '', 1), 7, false); zombie.animations.add('walk', Phaser.Animation.generateFrameNames('walk/go_', 1, 10, '', 1), 7, true); zomBody.sprite = zombie; zombie.body = zomBody;'spawn');{'walk'); //zombie.body.velocity.x = -100; //zombie.body.moveLeft(100); //zomBody.moveLeft(100); //zomBody.velocity.x = -100; console.log(zombie); }, this); } Personally I think that the problem lies with the body being set as it is, as this method feels like a buggy workaround to me. The only symptom of the problem I can see within the sprite object is that setting the velocity actually does nothing, whereas elsewhere in the code it works as expected. I wouldn't be exaggerating if i said i had spent 6 hours on this problem, and I'm about 2 hours away from quitting my job forever and ritually burning my PC. Any help at all would be great, cheers.
  21. Hello, today, they released the BOX2D commercial Plugin for Phaser: or at least came up with examples, so that somebody could start working with it. Anyways, I have been using P2JS on my ongoing development and have been pretty satisfied except that it is sometimes hard to work around issues with friction which applies on a body top but also side, so that a character will not slide on top but in return hangs on the side due to that friction, sure I found some workarounds but I was wondering if BOX2D would solve such issues better. Does someone have experience with both of the physics systems and if yes, what are the pros and cons of each? Thaks a lot!
  22. Good day. I have a question about custom shapes rendering. I need to make dynamic shape with multiple edges and render it on display. Is there a way to make a shape with "new Phaser.Physics.Box2D.Body(, null,, 500);" i.e. shape without underlying sprite and then fill it somehow? Currently I either get invisible shape or debug and get all objects outlined. All examples I see use game.debug.box2dWorld(); But I want only one shape to have outline.
  23. Hi, I just published short blog post on announcing my new Typescript defs for Phaser Box2D plugin. I remember, that few people asked for it here, on this forum. It may still contain some flaws - I already caught few of them during work on my game - but it is still very helpful. The blog post is here: And direct link to GitHub is here:
  24. i have two sprite on is dynamic and the second is static an d i want to put the dynamic sprite over the other when i drag it beside it i use setBodyContactCallback to check collision like that m_ship.body.setBodyContactCallback(enemy1, enemyCallback, this); in the enemyCallback function function enemyCallback(body1, body2, fixture1, fixture2, begin) { i wrote game.physics.box2d.weldJoint(body2, body1); but not work can any body know solution thanks in advance
  25. I searched the docs and could not find anything equivalent to Box2D's native ApplyAngularImpulse method. Are there plans to expose this at all? Is it safe to called it directly on instead?