Search the Community

Showing results for tags 'p2'.

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 335 results

  1. Hi, I want to make a pinball game with phaser and p2 js physics. I have a probleme with flips. To make the rotation movement, i must to change anchor to 0,0 with : this.flipGauche.anchor.set(0); but with this the sprite the anchor'sprite change but no the body
  2. How can I check if two sprite are overlapping or not at a given moment if both of them has special shape with loadpolygon? (eg. crosshairs rectangle vs. enemy on a click) Do I need to use P2? Maybe the solution is obvious, but I am absolutely beginner in Phaser.
  3. Is there a way to get collisions to work with p2, or to go through the list of active bullets and get thier x and y location, Or what do I loose if I switch from p2 to arcade. Thanks
  4. Hi All, I have just uploaded my new game Quick Pinball. It is classic pinball game. I used Phaser P2 Physics and Cocoon for wrapper. Here is the link: I hope you like the game
  5. How to use P2 Physics with each layer object? Code this.saws =; this.saws.enableBody = true;'saws', 4, 'saw', 0, true, false, this.saws); this.saws.forEach(function(saw) { saw.body.clearShapes(); saw.body.loadPolygon('physicsData', 'saw'); });
  6. Check out our new tutorial, Phaser Cars & Trucks with P2: We will cover constraining wheels to the truck body, increasing wheel grip, and creating a bouncy chassis effect that is seen in many popular games today. See what you will learn to create:
  7. Our new tool, Loon Physics, has just been released to open beta for free! Try it now to export P2 Physics body polygons for Phaser. Use a URL to test live without exporting files. Use Loon Physics here: Learn how to make a game with P2 Physics using this brand new tutorial:
  8. Hello, In the tiled map editor is a tilecollision editor i was just wondering if there is any way to get the stuff u do in there to work in phaser, or any other way to set a specific collision polygon to a tile.
  9. I'm working on a Pachinko-like game and have a question about physics. I'm new to Phaser, so if this is an obvious answer, sorry! I have a star-shaped pin wheel thing. I need it to be stationary but rotate around its anchor point when hit by an object (based on physics). How would I go about making it stationary, but allowing it to be rotated based on objects colliding with it? (I know how to get the polygon collision using the Physics Editor, I'm just not sure about the rotation part). Any help will be greatly appreciated! Thanks.
  10. Loon Ride, the epic loon game, has received major updates on all platforms! Collect loons, shoot cacti, and soar through endless mode. This game was made using Phaser. Read more about the game here: Play the game in your browser here: Get the game on Google Play here: Promo video:
  11. We recently released a tool for editing P2 Phyics body polygons called Loon Physics. Check it out here: Read a tutorial about P2 Physics bodies and Loon Physics here: Do you find Loon Physics useful? Do you encounter any bugs when using the tool? Any suggestions?
  12. hi, i'm coding a pinball game in js with phaser and p2physics. I search how i can do rotation with a anchor point. I want create the rotation for the flipper but method rotateLeft or rotateRight do the rotation by the center's sprites. I want create a rotation around topleft and top right point of the sprite to do a flipper movement. orry for my bad english, thx.
  13. I made an example of how you can mimic a skeleton/bodyparts using LockConstraints in P2 physics. I thought it might be useful to share it/ add to the Phaser examples , for people looking for ways to use joints/ lock constraints in their game. here is the example: The sprites I used are from my own game, but you could very well replace it with any other sprites... In the code I also explained how it works.
  14. Hello guys I'm making a platformer game, I struggled with making collision between the player and objects created in tiled but after that I got it working with a function I created, however, when I make the rectangle rotated in tiled, in the game it comes out away from its position, take a look: this is on tiled in the game it comes out like this here is my code, createCollisionObjects is where the magic happens var game = new Phaser.Game(70 * 10, 70 * 7, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render }); function preload() { // tilemap game.load.tilemap( 'map', 'assets/tilemaps/maps/lvl-1.json', null, Phaser.Tilemap.TILED_JSON ); // tilemap images game.load.image('new', 'assets/tilemaps/tiles/new.png'); game.load.image('sheet', 'assets/tilemaps/tiles/sheet.png'); game.load.image('s9af', 'assets/tilemaps/tiles/s9af.png'); // player spritesheet game.load.atlasJSONHash( 'player', 'assets/spritesheets/player_walk.png', 'assets/spritesheets/player_walk.json' ); } /* * GLOBAL VARIABLES */ var map; var player; var playerSpeed = 400; var jumpTimer = 0; function create() { game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setBoundsToWorld(true, true, true, true, false); game.physics.p2.gravity.y = 300; game.physics.p2.restitution = 0; game.stage.backgroundColor = '#ffffff'; map = createMap().map; var start = map.objects.objective[0]; player = createPlayer({x: start.x, y: start.y}); cursors = game.input.keyboard.createCursorKeys(); } function update() { player.body.setZeroVelocity(); if (cursors.up.isDown && > jumpTimer && checkIfCanJump()) { player.body.velocity.y = 600; jumpTimer = + 750; } if(cursors.left.isDown) { player.body.velocity.x = -playerSpeed;'walk'); } else if (cursors.right.isDown) { player.body.velocity.x = playerSpeed;'walk'); } else { player.body.velocity.x = 0; player.animations.stop(); player.frame = 0; }; } function render() { } function createMap() { var m, g, f, b, c; m = game.add.tilemap('map'); var mWidth = m.widthInPixels; var mHeight = m.heightInPixels;, 0, mWidth, mHeight); m.addTilesetImage('sheet', 'sheet'); m.addTilesetImage('new', 'new'); m.addTilesetImage('s9af', 's9af'); g = m.createLayer('ground'); f = m.createLayer('fringe'); b = m.createLayer('background'); g.resizeWorld(); f.resizeWorld(); b.resizeWorld(); createCollisionObject(m.objects.objects); return { map: m, ground: g, fringe: f }; } function createPlayer(pos) { var p = game.add.sprite(pos.x, pos.y, 'player', 'Symbol 2 instance 10000'); //p.scale.setTo(0.4, 0.4); game.physics.p2.enable(p); p.body.setZeroDamping(); p.body.fixedRotation = true; p.body.x+=p.width/2; p.body.y+=p.height/2; // animation p.animations.add( 'walk', Phaser.Animation.generateFrameNames('Symbol 2 instance 1000', 0, 7, '', 1), 10, true, false); //'walk-left'); return p; } function createCollisionObject(objects) { if (objects) { for(var i=0; i < objects.length; i++) { var p2 = game.physics.p2; var obj = objects[i]; var sprite = game.add.sprite(obj.x, obj.y, null); sprite.width = obj.width; sprite.height = obj.height; sprite.angle = obj.rotation; game.physics.p2.enable(sprite, false); sprite.body.x = sprite.x + sprite.width / 2; sprite.body.y = sprite.y + sprite.height / 2; sprite.body.rotation = obj.rotation; sprite.body.static = true; sprite.body.debug = true; } } } function checkIfCanJump() { var yAxis = p2.vec2.fromValues(0, 1); var result = false; for (var i = 0; i <; i++) { var c =[i]; if (c.bodyA === || c.bodyB === { var d =, yAxis); // Normal dot Y-axis if (c.bodyA === d *= -1; if (d > 0.5) result = true; } } return result; }
  15. Hi, I am getting some unwanted behaviour with groups and p2 physics. When the sprites is leaving the screen, I want to kill them and reset new ones. But when I kill the first one, and reset a new one, the physics goes haywire. Anyone got a suggestion on how to fix this? Check this pen for an example:
  16. I need to check if one object (Sprite/p2 body/shape) contains another object. In p2 documentation I found only Contact event, but I need to know when body inside sensor or other area. In Phaser I found Phaser.rectangle.containsRect, this is what I need but Rectangle do not support rotation as I understand. So fail (( With AS3 and Nape I did it this way: if(Geom.contains(outShape, inShape)){.....} How I can do it in Phaser and/or p2 physics ?
  17. Hi to you all. Hi have a question. I'm making a platformer game using phaser and , for now, arcade physics. I make my level in Tiled and export them in JSON. I noticed that since Tiled work with png tileset and that tiles are square. My character do not detect a slope or slante corner. It stands on a invisible cube border. What i was wondering is, is it possible for phaser to detect slanted slope using arcade or should i move to P2JS. Also how do I tell phaser to ignore the transparent part and collide only with the image? I tried making object layer coutouring all the platform for a more precise collision but it seems i'm not able to create a collision layer with a Tiled object layer. or maybe i'm doing it wrong. function create() { map = game.add.tilemap('niveau2'); map.addTilesetImage('tileset','background'); map.addTilesetImage('hints','hints'); backgroundLayer = map.createLayer('background'); collisionLayer = map.objects.evenement.find( o => == 'platform'); collisionLayer.visible = false; console.log(collisionLayer); map.setCollisionByExclusion([],true,collisionLayer); collisionLayer.resizeWorld(); //map.setCollision(1) player = game.add.sprite(32, - 150, 'star'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y=10050; // Our controls. cursors = game.input.keyboard.createCursorKeys(); } function update() { game.physics.arcade.collide(player, collisionLayer); //more code }
  18. Hi, 1 month ago, I started looking into physics coz I've wanted to make a pinball game (I own 5 real games and am a bit of Pinball freak). So I started looking at physics, which I never had used before (I made some other Phaser games before) Anyway, P2 seemed good enough and I also found this demo by forum member george : So I worked from that and I now have this : Still a work in progress, but It plays quite nicely I think.. What I would like to add is *active* elements that not just bounce the ball back, but kick it back when hit. I can register a hit and then need the bumpers and slingshots to kick the ball away (on top of the bounce) What would be the best way to achieve this ? I tried using body,reverse but that is producing strange effects.. I can think of these options : always apply the same restitution value for bumpers and slingshots (so not dependent on speed of ball) - but that's probably not possible create a virtual kicker using P2 that kicks the ball (seems pretty hard to do for a bumper because it's a circle that can be hit from any direction) create a reverse force for the pinball Anyone has any ideas or pointers ? Besides this - would box2d be better for pinball then P2 ? thanks for any input or feedback.
  19. Hi guys! I'd like to make a computer object in my game, such that when player approches to the computer,it triggers onEnter callback ( where I can for example show a message on screen to press certain key ) and when player goes away it triggers onLeave callback ( where I can hide the message ). In order to achieve that I need two colliders, one for regular collision ( red one ), and the other to detect if the player entered computer's zone ( green one, this is the one that I want to trigger callback ). = 9 * TILE_WIDTH + COMPUTER_WIDTH / 2, TILE_HEIGHT + COMPUTER_HEIGHT / 2, 'computer' ); ); = true; TILE_WIDTH, TILE_HEIGHT, COMPUTER_WIDTH / 2, COMPUTER_HEIGHT / 2 ); this.computersCollisionGroup = ); this.playerCollisionGroup, () => console.log( 'player in range' ) ); this.player.body.collides( this.computersCollisionGroup ); My question is: How do I turn off physical collision in green collider and what to do to make green collider trigger onEnter and onLeave callbacks ?
  20. symof


    A mobile only game(Chrome only), and the second that I made so far (mostly it's just me experimenting stuff xD ). It uses javascript api to detect motion and move a ball through a maze. The maze is re-generated on every run. I use p2js for physics and on the devices that I tried out works pretty well.
  21. Hey guys, I am developing this draft game demo and I need some advice/ feedback on some tips to make the collision a bit better. I'm using loadPolygon to load a custom body shapes for this sprite object and responding to collisions using onBeginContact to applyImpulse to the ball on a SPACEKEY.onDown The following is the code player.body.collides(ballCollisonGroup, this.headerBall, player) headerBall(bodyA, bodyB, shapeA, shapeB, equation) { let duration = 10; let localX = equation[0].contactPointA[0]; let localY = equation[0].contactPointA[1]; let forceX = 0.12 * this.headMass; let forceY = 0.8 * this.headMass; if(this.headerKey.isDown) // only if see is down apply additional force { duration = Math.min(this.headerKey.duration, 500); // apply time based on how long key pressed forceY = (1 * this.headMass).toFixed(2); // apply force of 1 velocity x mass of head (.53) forceX = (1 * this.headMass).toFixed(2); let impulse = [(forceX * duration), (forceY * duration )]; // calculate impulse bodyA.applyImpulse(impulse, localX, localY ); // apply it to ball } } I'm not sure if I am doing it right as I am not verse in Math Physics but i would like some feedback on the following: - Is my formula accuarate? Can I set varying impulses based on the contact shape? There is a sort of glitch if the ball comes into contact with his shoes and the ball ends up in the middle of his body which gets stuck. How can I avoid this? The key down condition seems to be glitchy is there anyway to make this a bit more "safe" to detect and capture? I need to apply some force to the ball ONLY when the space key is pressed. Thank you in advance for your feedback.
  22. Hi! If I use p2 physics what is the most effective way to add slopes to my tilemap? I use tiled. I saw a solution here (below) where you make the tile layer with the slope tiles non-collidable, and you make an object layer on top of that where you draw polylines, and make the object layer collidable, but thats not that efficient if you design a level and want to try out a lot of variations. So my question is, is there a more efficient way of doing this? For example like in ninja physics where you can associate the tiles with different shapes.
  23. Hi all, I'm trying to have my bullets group that already collides with the enemies, both of them are a group, but now that I want to add a static block or obstacle, it simply wont collide or overlap or nothing, what I want is that when the bullet collides or overlaps it gets destroyed or at least bounce into the obstacle, see code below: ////////////////My Bullets//////////These work fine and collide correctly with my enemies.////// createBullets: function() { this.bullets =; this.bullets.enableBody = true; this.bullets.physicsBodyType = Phaser.Physics.P2JS; this.bullets.createMultiple(100, 'bulletSprite', 0, false); this.bullets.setAll('anchor.x', 0.5); this.bullets.setAll('anchor.y', 0.5); this.bullets.setAll('outOfBoundsKill', true); this.bullets.setAll('checkWorldBounds', true); }, fireBullet: function(){ if (this.bulletTimer < { this.bulletTimer = + 500; this.bullet = this.bullets.getFirstExists(false); if (this.bullet) { this.bullet.reset(this.tanke.x, this.tanke.y - 20); this.bullet.body.setCollisionGroup(this.bulletCG); this.bullet.body.collides([this.figuraCG]); this.bullet.body.velocity.y = -3500; } } }, //////This is the block or obstacle this just wont work no matter what I try/////////// makeOneBloque: function(){ this.bloque =, 950, 'Blokes'); this.bloque.enableBody = true;, true); this.bloque.body.kinematic = true; this.bloque.body.collides(this.bullets, this.collisionBulletBloque, this); //////I tried overlaps and it just crashes the lvl }, collisionBulletBloque: function(bullet) { bullet.sprite.destroy(); }, I would greatly appreciate any help or suggestions.
  24. Rafaelx


    Trying to create a group, but keeps saying it is undefined got any suggestions? Please see code below. this is defined in the create function: this.bloqueCG =; makeOneBloque: function(){ this.bloque =; this.bloque.enableBody = true; this.bloque.physicsBodyType = Phaser.Physics.P2JS; this.bloque.create(200, 950, 'Blokes'); this.bloque.create(550, 950, 'Blokes'); this.bloque.create(900, 950, 'Blokes'); this.bloque.body.setCollisionGroup(this.bloqueCG); <<<<----I get error here :( this.bloque.body.collides(this.bulletCG, this.hitBloke, this); this.bloque.body.kinematic = true; this.bloque.setAll('anchor.x', 0.5); this.bloque.setAll('anchor.y', 0.5); this.bloque.setAll('outOfBoundsKill', true); this.bloque.setAll('checkWorldBounds', true); },
  25. Runnable code here: I'm using P2 physics and I'm trying to raycast to the mouse position. I've got a tilemap with physics bodies set up, and they show fine with debug draw on. However, the ray never hits any of the tile bodies, nor the player body. It only hits the top and left side of the world bounds. Screenshots attached. Is there anything obvious I'm doing wrong, or is this a bug?