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 create a tilemap with 4 layers with one for collisions ( named : collisions ). The layer with pink tiles is my collisions layer, and the tile ID is 515. Then I add a player and active collisions. function preload() { game.load.tilemap('map', gamePath + 'assets/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', gamePath + 'assets/tiles.png'); game.load.spritesheet('cars', gamePath + 'assets/cars.png', 180 / 5, 73); } function create() { game.physics.startSystem(Phaser.Physics.P2JS); map = game.add.tilemap('map'); map.addTilesetImage('tiles'); layer = map.createLayer('collisions'); console.log(layer); layer.resizeWorld(); map.setCollision(515,true); game.physics.p2.convertTilemap(map, layer); player = game.add.sprite(1100, 800, 'cars'); game.physics.p2.enable(player,true);; cursors = game.input.keyboard.createCursorKeys(); } I do not understant why there is not collisions between my player and my collisions layer. thx for your help.
  2. I'm using P2 physics, and I'm creating a relatively intricate border around the screen that I want balls to bounce against. I am scaling all assets on the screen for 3 different aspect ratios, depending on the user's screen size. I create the border like this: bgOverlay = otherSpriteGroup.create(gameWidth / 2, gameHeight / 2, "bgOverlay"); bgOverlay.anchor.setTo(0.5, 0.5); bgOverlay.scale.setTo(scale.x, scale.y); bgOverlay.body.clearShapes(); bgOverlay.body.loadPolygon("physicsData", "bgOverlay"); bgOverlay.body.setCollisionGroup(otherCollisionGroup); bgOverlay.body.collides(bubbleCollisionGroup, otherHitBubble, this); bgOverlay.body.static = true; The trick is that I scale all assets using a Phaser Point, scale.x and scale.y. But when I load in the polygon data using bgOverlay.body.loadPolygon, it takes in actual pixel values, and I can't scale bgOverlay.body. I am not sure how to scale the numbers in the physics data. Any ideas?
  3. Hi guys, I'm very new to this so I'd really appreciate if someone would be able to point me in the right direction. I have a 2d top-down car game where the track boundaries is a polygon made with physics editor. I need to get the distances from the car at various angles to the boundaries of the track. I've looked for line polygon intersection but I haven't been able to find anything. Any idea where I should start here?
  4. Using P2 Physics, what's the best way to move a sprite, similar to sprite.body.moveRight, sprite.body.moveLeft but in parallel with another sprite that has a rotation (which constantly changes). I want to be able to move the purple line up and down along the yellow line, in parallel and at a fixed distance while they both rotate. Anya ideas? Thanks
  5. hi guys, I wonder is there any way to check whether 2 sprite in different groups are overlap, in the p2 system, currently I am using game.physics.p2.setPostBroadphaseCallback(this.checkOverlap, this); to do it, however I think it maybe expensive because I need to check whether the 2 sprites are from same group (the same group should not do anything). and I do not need collide when 2 sprite impact, I just need them to trigger my function. so I wonder is there any way to do thing like body.collide in arcade system, thanks.
  6. Is there a way of finding the point of contact between 2 bodies? In some of the p2 demos it draws a line from body centre to contact, so clearly the data is in there somwhere, but I can't seem to find a way of extract it...
  7. Hi, I'm just working with P2 and have hit a bit of a wall. I need to check whether all the bodies in the world are at rest (i.e. no longer moving)... in Box2D (as far as I recall) there was either a world.sleeping property (or perhaps so you could check when/if this had happened. There doesn't seem to be an obvious way of doing this in P2. One solution would be to loop thru all the bodies checking for velocity == 0, but this seems a little cumbersome. Have I missed an obvious way to do this?
  8. Hi friends, I'm very new to Phaser (but I have a long programming background) and right now I'm trying to work on a new game concept of mine. Basically, it is a regular Pong but with few twists. I have attached an image below of the main game for further clarifications. gifs upload 1) As you can see, the shape of the paddles is a polygon. As such, I have to use P2 physics for them as the simple arcade won't suffice because of their peculiar shape. 2) Now since the paddles are using P2, I'm forced to use P2 for the ball as well because they both need to collide and I can't collide a P2 and Arcade sprite 3) Now the problem is, when I apply a velocity to the ball and make it move at a specific direction, I want it to collide with the body ahead (either one of the paddle or wall) and continue on it's path with the SAME velocity infinitely . Right now, it slows down momentarily till it comes to a full stop. I can achieve this 'continuous velocity' for the ball when it is in arcade but I can't use arcade since my paddles are P2 and so I"m forced to find a method to achieve this in P2 for the ball. My Ball sprite code is : this.Ball = this.add.sprite( / 2, / 2, 'Ball') this.physics.p2.enable(this.Ball); this.Ball.body.clearShapes(); this.Ball.body.loadPolygon('physicsData', 'Ball'); this.Ball.anchor.setTo(0.5, 0.5) this.Ball.checkWorldBounds = true; this.Ball.body.collideWorldBounds = true; this.Ball.body.mass = 0.01 this.Ball.body.restitution = 1 this.Ball.body.damping = 0 this.Ball.body.velocity.x = 400*(Math.cos(0)); this.Ball.body.velocity.y = 400*(Math.sin(0)); Thank you and warm regards
  9. Hi all I have a small problem, I'm trying to determine my score by the type of sprite that you hit with your bullets, this type is defined to the player by a small sprite on top of the screen, kind of like if you hit matching one you get 100 points if not 50 points see my code below. Can someone correct me in what I'm doing wrong? ///////I load my atlas this.load.atlas('Monsters', 'asset/game1/Monstruos/monstruos.png', 'asset/game1/Monstruos/monstruos.json'); //////This is my sprite that determines the type createFiguraCompare: function(){ // create a sprite, random frame 0..4 this.figuritaspega =, 0, 'Monsters'); this.figuritaspega.frame = this.rnd.integerInRange(0,4); // create a group this.figuritaspegaG =; // <- function call this.figuritaspegaG.add(this.figuritaspega); // scale entire group and reposition group this.figuritaspegaG.scale.set(0.5 , 0.5 ); // notice that the sprite position is relative to the group position this.figuritaspegaG.x = 800; this.figuritaspegaG.y = 140; }, ////////this is my moving sprites that you must hit with the bullets makeOneFigura: function() { this.figura =; this.figura.enableBody = true; this.figura.physicsBodyType = Phaser.Physics.P2JS; // for (var i = 0; i < 5; i++){ this.figura.createMultiple(100, 'Monsters', 0, false); // } this.figura.setAll('anchor.x', 0.7); this.figura.setAll('anchor.y', 0.7); this.figura.setAll('outOfBoundsKill', true); this.figura.setAll('checkWorldBounds', true); }, makeFiguras: function(x, y){ if (this.timerFiguras) { this.figuras = this.figura.getFirstExists(false); if (this.figuras) { this.figuras.reset(500, 0); this.figuras.frame =,4); this.figuras.body.setCollisionGroup(this.figuraCG); this.figuras.body.collides(this.bulletCG); this.figuras.body.velocity.y = 1400; } }; }, ////and my collision handler My problem is mainly here collisionBulletFigura: function(bullet, figura, score, scoreText, figuritaspegaG) { if (this.figura.currentFrame === this.figuritaspegaG.currentFrame){ figura.sprite.kill(); bullet.sprite.kill(); this.score += 100; this.scoreText.text = this.score; }else { figura.sprite.kill(); bullet.sprite.kill() this.score += 50; this.scoreText.text = this.score; } },
  10. Hi everyone, I'm new to Phaser, and I'm using P2 for my collision events. Now I'm justing doing a test in which a group of objects colliding with the world boundary. It works fine but the objects lose a lot of energy and velocity when collides with the world boundary. I just want the objects to bounce back with same speed, like 'setBounce' in arcade. I've tried the following : 1. Set the restitution, but I can just see little difference between different restitution values. 2. Contact Material. I referenced to this page physics&f=contact+material.js&t=contact material It looks fine but it seems that one contact material contains only one sprite? Is there any way to add a collision group to one contact material? Or are there other ways to do this?
  11. Hi everyone, Anyone knows how i could convert a object layer from tiled(with rectangle, circle...) into a P2 object/sprite or whatever ? I would like that my player can check if there's an overlap with theses objects :/
  12. GameDemon

    p2 body sleep

    How do you tell if a P2 body is sleeping? I cant see any property for that on Body, only `allowSleep` and `sleepSpeedLimit` (both of those undocumented btw). I just have some simple circle bodies with gravity atm, I wanted to colorise the sleeping bodies for debug purposes. I tried turning p2 sleepmode on by declaring `game.physics.p2.sleepMode = 2;` I'm not sure how to set this properly, I saw World.BODY_SLEEPING=2 in the Phaser source, with standalone p2 its set via `p2.World.BODY_SLEEPING;`
  13. I'm having a bit of trouble with tilemap collisions. I'm using P2 and a json tiled tilemap. Strangely, it seems to work with small, simple tilemaps but as soon as I boost the complexity it seems to stop working. I've got a simple car being driven by physics that turns one way when you touch and the other when you don't. Help? Here's the create code: create: function(){ game.physics.startSystem(Phaser.Physics.P2JS); //!THIS STUFF WORKS WITH TEST MAP = this.add.tilemap('city');'roguecity'); this.decorationLayer ='decoration'); this.collisionLayer ='collision'); this.collisionLayer.resizeWorld();, 12); this.physics.p2.convertTilemap(, this.collisionLayer); this.stage.backgroundColor = "#d3d3ff"; this.cursors = game.input.keyboard.createCursorKeys(); game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]); //map stuff //create the layer //this.backgroundLayer ="background"); //car stuff = game.add.sprite(60,35,"car"); game.physics.p2.enable(;,0.5); = true; }, Thanks!
  14. Hi, my problem is collision's callback works only on "bounce" or on the first touch of every collision, idk. My code checks, when player collides platform, then (in other function) if arrow is down it sets sprite's velocity x to 200. This sprite changes velocity only if it "bounces", but doesn't when it's standing on this platform. I set console's log in my function and it also appears, when player is bouncing, not standing . I'm switching from arcade to P2 right now and I'm such a newbie. Could anyone help? (Sorry for my english) code here: demo here:
  15. Hey My question is pretty straigh forward, is there any alternative to PhysicsEditor, that is at least Free if not OpenSource. Thanks in advance!
  16. Hey there So, this is my first post in here, i hope everybody is good out there, let's go straight into the issue. I'm new to, and I'm intending to use it to create a hill climber clone. I have successfully create car like shapes (following a couple of online tutos) but still very confused about how to create the land on which the car will run. To make it clearer, here's an illustration of what i exactly want: So basically, the original game introduces 2+ types of ground, that are the bridges, land, water, ... I need to implement only two types. I know how to "materialize" the body and everything that should go after i declare them, which is my problem. On examples page there's quiet half the solution to my problem but uses Box2D which is paid (and i can afford it right now, else, i would love to get it!)
  17. If I apply an impulse/force on a body, I see that the body is moving as expected, but is stopping (velocity=0) very, very slowly. I can still see the velocity be something like 0.00003 and moving down to zero. Applying damping does help, but it does affect my gameplay, since it will stop quickly only if I set it at a very high damping value, and I would like it to simply be stable after applying a force instead of having to wait a long time till the velocity = 0, with minimal damping. How can I fix this? Edit: Solved Applying damping did help, but I just had to lower the mass to get the effect I was looking for. Thanks!
  18. Heyo, I'm currently building a side scrolling space shooter and desired to have pixel perfect collision detection to allow a better experience dodging bullets and correctly colliding with enemies. To do this I used the P2 engine with loadPolygon functionality. However I have run into a problem were I can't stop the physics (velocity) from transferring from my bullet to my enemy and/or rotating either of the objects which becomes more noticeable when re-using pools of objects (although the objects in question retain a angle/rotation of 0). Any solutions I have come across to make the bullet and enemy static has end up with a no collision detection scenario. -Once you set two different body's to static = true they no longer fire collision events. -If body's kinematic = true then the same happens with no fire collision events. I've reviewed the examples page, however the kinematic and/or static demo's only work if your not kill/reset 'ing the objects. Once that happens there is no collision or in my case the player is auto firing currently so it's bullets are kill/reset before enemies are even placed on the screen. Much googling has come across postings of similar issues in the 2014 and 2015 and I was wondering if there is any resolution to this problem yet? Having two static/kinematic P2 bodies collide without transferring any velocity to each other, just need a collusion detection event for firing custom logic (kill bullet, damage enemy); Snippet of working example prier to static/kinematic setting: (similar code is used for enemies / player and enemy bullets and collision work 100% until static/kinematic is turned on to all parties)[this.player], true); this.player.body.clearShapes(); this.player.body.loadPolygon('enemy_physics', 'player'); // this.player.body.static = true; // this.player.body.kinematic = true; this.player.body.setCollisionGroup(this.playerCollisionGroup); this.player.body.collides([this.enemyBulletsCollisionGroup, this.enemiesCollisionGroup], this.killPlayer, this);
  19. Hey, I'm developing a Phaser game and been stuck for way too long in this error in my code. Basically I create the player object and everything else from classes to groups and add them to collision groups. Finally I make them collide with body.collides where the callback should happen. I've tried firing the callbacks with just the function name, this.function, function(this.meteors) but nothing seems to work so that the callback gets fired only on contact. Either it fires with every create or never. Here's the main game.js: BasicGame.Game = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: var playerSpawnX = 300; var playerSpawnY = 300; = game; // a reference to the currently running game (Phaser.Game) this.player = new BasicGame.Player(,playerSpawnX,playerSpawnY); this.gem = new BasicGame.Gem(; this.meteor = new BasicGame.Meteor(; this.hud = new BasicGame.Hud(,this.player); }; BasicGame.Game.prototype = { create: function () { this.timer; this.timer2; = 0; //this.score = 0; var highscore = localStorage.getItem("highscore");;; this.ships =; this.ships.enableBody = true; this.ships.physicsBodyType = Phaser.Physics.P2JS; this.ground =, 2205, 600, 220, 'layers', 'maa'); this.ship = this.ships.create(this.player.create());, false);, 0, 600, 2400); //this.physics.startSystem(Phaser.Physics.P2JS); //////////////////////////////GLOBAL PHYSICS//////////////////////////////////, false, false, true, false); //GLOBAL PHYSICS GRAVITY this.physics.p2.gravity.y = 250; // Create our collision groups. this.shipCollisionGroup =; this.meteorsCollisionGroup =; this.gemsCollisionGroup =; this.ship.body.setCollisionGroup(this.shipCollisionGroup); // This part is vital if you want the objects with their own collision groups to still collide with the world bounds // (which we do) - what this does is adjust the bounds to use its own collision group. this.shipCollisionGroup.collideWorldBounds = true; this.meteorsCollisionGroup.collideWorldBounds = false; //this.gemsCollisionGroup.collideWorldBounds = false; //to make ship hit the sides of screen; //gems group this.gems =; this.gems.enableBody = true; this.gems.physicsBodyType = Phaser.Physics.P2JS; //meteors group this.meteors =; this.meteors.enableBody = true; this.meteors.physicsBodyType = Phaser.Physics.P2JS; this.meteors.gravity = 0; this.timer =; // Set a TimerEvent to occur for meteors and gems this.timer.loop(3000, updateScoreCounter, this); this.timer.loop(1000, spawnGems, this); this.timer.loop(7000, spawnaaMeteoriitteja, this); this.timer.loop(5000, spawnaaPaikallisiaMeteoriitteja, this); this.timer.start(); function updateScoreCounter() {; this.player.score = this.player.score + * 10; console.log(this.player.score); } function spawnaaMeteoriitteja() { for (var i = 0; i < 1; i++) { var meteor = this.meteors.create(this.meteor.create());; meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup,this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnaaPaikallisiaMeteoriitteja() { for (var i = 0; i < 1; i++) { var static = "true"; var meteor = this.meteors.create(this.meteor.create(,, static));; meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup, this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnGems() { for (var i = 0; i < 2; i++) { var static = "false"; var gem = this.gems.create(this.gem.create(,, static));; gem.body.setCollisionGroup(this.gemsCollisionGroup); gem.body.collides([this.gemsCollisionGroup, this.shipCollisionGroup, this.meteorsCollisionGroup ]); gem.body.collideWorldBounds=false; } } this.hud.create(); this.ship.body.collides([this.shipCollisionGroup,this.meteorsCollisionGroup], hitMeteor, this); this.ship.body.collides([this.shipCollisionGroup,this.gemsCollisionGroup], hitGem, this); function hitMeteor(body1, body2) { //console.log(body1); console.log("hit meteor"); } function hitGem(body1, body2) { console.log("hit gem"); } }, update: function () { this.player.update(); }, render: function() { this.hud.render(); this.player.render(); }, quitGame: function (pointer) { } };
  20. Hi, I want to make a game similar to flappy bird but I've got a few problems with it. (Acutally, whole game is a problem :/ ) Would somebody mind helping me on priv? Code here:
  21. 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.
  22. I'm trying to make a 2d space game involving a sort of space dogfight between the player and some ai bots. I need help with the enemy ship automatically rotating towards the player, but not being exactly pointed towards the ship 24/7. I want the enemy ship to have some "lag" in its response to the player's movement so it's more realistic. Right now I have a model which is not realistic and would probably be too hard for the player to win: update: function(){ //blah blah var tempAngle = Math.atan2(fightSprites.player.y-fightSprites.enemy[i].y, fightSprites.player.x - fightSprites.enemy[i].x); //gets angle between player and enemy fightSprites.enemy[i].body.rotation = tempAngle + (3.141/2); //too precise }
  23. Good day, I have been struggeling with this issue for a few days, I am also quite new to Phaser, so please forgive me if this is a newbie question. I am currently working on a project regarding a destroyable map with p2 physics. I have been using Physics editor to capture the maps size in a JSON file and all that seems to be working fine, also I am creating the map as BitmapData object which also is working fine. But once a part of the map is being destroyed, it needs to recalculate the physics properties which obviously doesn't happen. The solution for me - I am going to get the boundaries of the map (its a small scrollable map not more than 1.5k pixels in width) and triangulate the smaller objects which create the shape myself, which means that if a part of the map is destroyed it will recalculate the physics properties. The issue here is that I simply can't get the boundary pixel positions of a map this size for the triangulation library, my browser simply crashes, for smaller objects it actually works fine and everything is working smooth! Only if I put larger pictures in the example, it crashes... I am using contour.js marching ants algorithm from D3 an example is demonstrated down below to get the contour. Maybe there is a better solution to detecting contour pixel positions of larger objects in Phaser? Why is this example not working with larger png objects? And yes.. I also need to detect the transparent area
  24. HI everyone, I'm having an issue When the wheel and arrow collision with P2, the wheel can't slow down. How can I make it slow down? Example: please tell me what's wrong with it,thx!
  25. I'm making a game with a lot of asteroids. I noticed that my fps drops the more asteroids I add when running on the 2015 i7 Macbook Pro. That probably means that on less powerful laptops will lag a lot? My asteroids are similar to the ones in the game Asteroids, however I wanted them to have a somewhat realistic collision body shape that represented the sprite shape. On the Phaser p2 examples I noticed that the json for physics bodies' shapes were broken into smaller shapes like this { [1,2 , 3,4 , 5,6], //pretend that this is a triangle [7,8 , 9,10 , 11,12], //pretend this makes another triangle [13,14 , 15,16 , 17,18] //pretend this makes another triangle } //pretend if you put all of the those shapes together it would make another shape as opposed to just having it as one complex shape like { [1,2 , 3,4 , 5,6 , 7,8 , 9,10 , 11,12 , 13,14 , 15,16 , 17,18] //pretend this makes a shape } Which is better for performance? Also I want to have maybe around 200 asteroids in my game at a time, not to mention some other bodies as well. Should I reduce the amount of vertices of the asteroid's collision bodies? Would setting it to be a circle be less power demanding? The game works fine on my desktop, but that has a gtx 970 and I doubt most people who play my game will have that sort of power.