Search the Community

Showing results for tags 'p2'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 335 results

  1. Hi guys, I have not worked ImpactEvents handler prompt in what may be the case: for(var i=0; i<enemies.length; i++) { for(var j=0; j<borders.length; j++) { enemies[i].body.createBodyCallback(borders[j], this.hitEnemy, this); } } game.physics.p2.setImpactEvents(true); hitEnemy: function(body1, body2) { console.log('collide borders with enemy'); },
  2. Hi guys. Object does not collide with the boundaries of the world in my mobile project. Please tell me what could be the case, for example, I wrote a short code, but the sprite passes through the boundaries of the world without collide with them. /** * Created by Buggy on 14.08.14. */var hero;var cursors;BasicGame.GameTest = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: this.game; // a reference to the currently running game this.add; // used to add sprites, text, groups, etc this.camera; // a reference to the game camera this.cache; // the game cache this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it) this.load; // for preloading assets this.math; // lots of useful common math operations this.sound; // the sound manager - add a sound, play one, set-up markers, etc this.stage; // the game stage this.time; // the clock this.tweens; // the tween manager this.state; // the state manager this.world; // the game world this.particles; // the particle manager this.physics; // the physics manager this.rnd; // the repeatable random number generator};BasicGame.GameTest.prototype = { create: function () { var back = this.add.sprite(0, 0, 'game', 'back.png'); this.physics.startSystem(Phaser.Physics.P2JS); this.physics.p2.restitution = 0.8; hero = this.add.sprite(200, 200, 'game'); hero.anchor.setTo(0.5, 0.5); hero.pivot.y = 10; hero.animations.add('idle', Phaser.Animation.generateFrameNames('tomato_idle/', 0, 11, '', 4), 15, true); hero.animations.play('idle'); // Create our physics body. A circle assigned the playerCollisionGroup game.physics.p2.enable(hero); // This boolean controls if the player should collide with the world bounds or not hero.body.collideWorldBounds = true; cursors = game.input.keyboard.createCursorKeys(); }, update: function () { hero.body.setZeroVelocity(); if (cursors.left.isDown) { hero.body.moveLeft(200); } else if (cursors.right.isDown) { hero.body.moveRight(200); } if (cursors.up.isDown) { hero.body.moveUp(200); } else if (cursors.down.isDown) { hero.body.moveDown(200); } }};
  3. Please tell me how I can get impulse value from contact between two bodies?
  4. Hi guys, please tell me how can I get a list of p2 bodies in a given region.
  5. i have one little tiled background image and two layers in tiled .. all of them are only used as background images.. all the collisionareas are polyline objects on different layers.. the problem is always the same.. the performance is so poor - the game is almost unplayable on a nexus7 (this is no low end device you know?!) of course my levels are quite big but this shouldn't matter at all because it's always just the camera view (800x480) that's beeing rendered but hey.. it does matter.. because scrolling tilemap layers still sucks hard.. so i am searching for a neat workaround.. i exported the whole map as jpg and every level got this hughe jpg as background - this works .. i've got almost 60fps on the nexus7 BUT every jpg eats up to 900kb so this is no good way to go.. right? (imagine 40 levels would need 40Mb space on your device .. and additional 20 for cocoonjs.. ) therefore i want to merge down the tilesprite with the background layers from tiled on load and get rid of the layers - scroll only one very big image.. because thats a LOT faster.. or any other idea would be very appreciated !! (otherwise my game will never go mobile )
  6. Hi, I just creating pinball game with Phaser... I'm using P2 physics. I have one sprite BALL: this.ball = game.add.sprite(x, y, 'ball'); game.physics.p2.enable(this.ball, false); this.ball.body.setCircle(10); this.ball.body.fixedRotation = true;But in one case I need to make this ball to ignore collisions with all elements... (ball should to pass through other sprites without collisions) I just need to turn off gravity, collision and then randomly move ball to different place and then turn gravity/collisions ON. I'm trying to create ball movement in rails above other elements.
  7. Hi guys, I'm trying to make a conveyor belt in contact with which the hero would begin to roll var mat1 = game.physics.p2.createMaterial('hero_material', hero_b.body);var mat2 = game.physics.p2.createMaterial('transp_material', obj.body);var contactMaterial = game.physics.p2.createContactMaterial(mat1, mat2);contactMaterial.surfaceVelocity = 100;this.physics.p2.world.addContactMaterial(contactMaterial);I wrote this code but it does not work, please help to understand what I'm doing wrong. Cheers
  8. while i can do the following for constraints: var allConstraints = game.physics.p2.getConstraints(); if (allConstraints.length > 0){ for (i=0; i<=allConstraints.length; i++){ game.physics.p2.removeConstraint(allConstraints[i]);} }it seems that springs work different although the documentation says it works exactly the same way: var allSprings = game.physics.p2.getSprings(); if (allSprings.length > 0){ game.physics.p2.removeSpring(allSprings); }removeSpring does not take A spring .. it takes a spring array... so how would i remove a single spring then?
  9. Hi all, does not work OutOfBounds event for the P2 physics. Im add it so: hero_b.events.onOutOfBounds.add(this.restartGame, this);
  10. Hi, I'm just getting to grips with the P2 physics system. I am trying to get two boat sprites to race each other, but as they both have bodies they just collide. I would like them to collide with the sea sprite only. I have tried to use collisionGroups, but I don't really understand how they work. The code below is my latest attempt to do this: this.game.physics.p2.enable([this.boat1,this.boat2, this.sea], false);var demoGroup = this.game.physics.p2.createCollisionGroup();this.sea.body.setCollisionGroup(demoGroup);this.jetski.body.collides(demoGroup);this.jetskiB.body.collides(demoGroup);I can't help but feel there must be a really simple solution to this - but I can't find it. Any help appreciated,
  11. Before creating an issue on github, decided to put it here (as suggested here https://github.com/photonstorm/phaser/blob/master/CONTRIBUTING.md) Class: Phaser.Physics.P2 Method: constructor Issue: physics config's user-defined options (mpx, mpxi, pxm, pxmi) get deleted in Phaser.Physics.P2 constructor. Proof: Why: game class instance passes the physics config to Phaser.Physics instance, then the config gets passed to Phaser.Physics.P2. Within this chain no other props are created, as a result 'broadphase' prop is never present in the physics config and always created by the p2 class. So, when a new p2 instace is created, the config with your custom mpx, mpxi, pxm, pxmi props gets replaced with a new config of { gravity, broadphase } only. As a result p2 uses default mpx, mpxi, pxm, pxmi methods (so they don't get overriden) How-to-fix: switch from config replacement to property adding. Current code: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */this.game = game;// @note// what if i already defined 'gravity' and 'broadphase' is not defined (btw it's never defined until this point)// my gravity prop will be also overridenif (typeof config === 'undefined' || !config.hasOwnProperty('gravity') || !config.hasOwnProperty('broadphase')){ config = { gravity: [0, 0], broadphase: new p2.SAPBroadphase() };}The fix: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */this.game = game;// config exists? if not - create oneif (typeof config === 'undefined'){ config = {};}// we got gravity? if not - define [0,0]if (!config.hasOwnProperty('gravity')){ config.gravity = [0, 0];}// we got broadphase? if not - create a new instanceif (!config.hasOwnProperty('broadphase')){ config.broadphase = new p2.SAPBroadphase();}// ... now mpx, mpxi, pxm, pxmi props will override the default methods properly// Pixel to meter function overridesif (config.hasOwnProperty('mpx') && config.hasOwnProperty('pxm') && config.hasOwnProperty('mpxi') && config.hasOwnProperty('pxmi')){ this.mpx = config.mpx; this.mpxi = config.mpxi; this.pxm = config.pxm; this.pxmi = config.pxmi;}
  12. this is the line that worked perfectly in 2.0.5 layerobjects_tiles = game.physics.p2.convertCollisionObjects(map,"objects");now i get : TypeError: a is undefined phaser.js:65567 if i comment out this line my game works fine... (without the objects of course) those objects are polyline objects created with tiled. edit: i tried to remove all the polylines from the layer "objects" and my game loads.. so what is wrond with tiled polylines in phaser 2.0.7 ??? a can place rectangles or circles without getting the error but those objects will never collide in phaser because they are not implemented.. how do i fix that? thx
  13. Hi, I'm newbie in Phaser (excuse my english)... Currently I'm developing pinball game. I have created flippers (paddle) via revolute constraints and ball in P2 physics... Everything works perfect but I need to make flippers more powerfull when they hit to ball (I need ball acceleration)... currently CreatePaddle = function(game,x,y, side) { Phaser.Group.call(this, game); this.side = side; this.flipped = false; this.sprite_two = game.add.sprite(x, y, 'paddle'); game.physics.p2.enable(this.sprite_two, true); //this.sprite_two.body.clearShapes(); if(side == 'right') { this.sprite_two.body.loadPolygon('physicsData', 'paddle2'); this.maxAngle = 30; this.pivotOffsetX = 50; this.sprite_two.scale.x *= -1; this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y); this.pivotOffsetX = 50; } else { this.sprite_two.body.loadPolygon('physicsData', 'paddle'); this.maxAngle = -30; this.pivotOffsetX = -50; this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y); } this.game.physics.p2.enable(this.pivotPoint); this.pivotPoint.body.static = true; this.pivotPoint.body.clearCollision(true,true); this.flipperConstraint = this.game.physics.p2.createRevoluteConstraint(this.sprite_two, [this.pivotOffsetX, 0], this.pivotPoint, [0, 5]); this.flipperConstraint.upperLimitEnabled = true; this.flipperConstraint.lowerLimitEnabled = true; return this.flipperConstraint;}Ball is created like this: //ball - circlecircle = game.add.sprite(470, 300, 'circle');circle.anchor.setTo(0.5, 0.5);game.physics.p2.enable(circle, false);circle.body.setCircle(16);circle.body.fixedRotation = true;Flippers are loaded like this: this.paddle1 = new CreatePaddle(game, 270, 2390, 'left');this.paddle2 = new CreatePaddle(game, 460, 2390, 'right');But how can I add more power to ball which collide with my flipper (paddle) ? Should I create custom material for flipper or is there easier way? Thanks for answers.
  14. It's even kinda funny to ask such a thing, but... Phaser.Physics.P2.Body class has two useful methods to convert points to local/global metrics (docs). For instance it's said [i][b]toWorldFrame(out, localPoint)[/b][/i]/* Transform a local point to world frame. */// out:Array - The vector to store the result in.// localPoint:Array - The input local vector.Ok, fine. I've created a new body with a (0.5,0.5) anchor, moved it to 100:100 px, then i try to find out what will be the (0,0) local body point in global coordinates - obviously the point is 100:100. Let's check: // create a spritevar s = game.add.sprite(0, 0, '');// position at 100:100s.x = s.y = 100;// enable p2 to create the bodygame.physics.p2.enable(s, true);// now try to find out the local 0,0 in world metrics// holds the global point (dunno why, but it's an array rather than Point)var v = [];// relative 0:0 point in global coordinates -- should be 100:100s.body.toWorldFrame(v, [0,0]);// traceconsole.error('result', v);// wtf is this?! O_o// result [-5, -5] Same with the toLocalFrame method. So: - what do these methods calculate?! O.o - are there properly working localToGlobal(p:Point) and globalToLocal(p:Point) methods in phaser or i should implement them myself?
  15. So, i'm trying to make a top-view car game prototype using the P2 physics engine and i've faced some weird bug? with the RevoluteConstraints. The idea is simple: create a car body sprite, create two tires and attach them to the car body, then apply car physics simulation on those tires and let the body follow. And the problem is that when tires are joint to the car, they are positioned wrong (which is weird) + the car starts rotating and the reason for that i just can't understand as: tires are positioned symmetrically + both RevoluteConstraints have the same forces that should be applied to constrain the bodies. May be i'm getting something wrong? I wouldn't make this topic if there were more advanced examples covering the P2 physics or at least examples in the docs/source code (yep, i've already googled for a solution). Here's a picture And here's the code (also available here http://pastebin.com/qjqeF5bc):
  16. Collision between my hero and polygon (ramp) penetrates through the polygon. Here is an image of what I mean. This loads the json file; this.game.load.physics('rampPolygons', 'assets/gameplay/ramps/exports/ramps_physics.json'); This is the co-ordinates for the polygon. { "ramp0": [{"density": 2, "friction": 0, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 },"shape": [ 0,0, 80,-30, 160,-90, 160,0, 0,0 ] } ] } This applies the polygon to the ramp spriteramp.body.clearShapes();this.body.loadPolygon("rampPolygons", ramp0 );
  17. Hi all, I've come across a problem with groups and P2 bodies. Basically, I have a group, to which I add a Sprite with a P2.Body. So when I move my group, the sprite is actually moving with it, but its body does not budge an inch. Is there a fix to this? Cheers
  18. Hi! I have got sprite which is moving with constant speed using: moveLeft Now I want to apply force to it to simulate effect of pushing it away from player. I tried: zombie.sprite.body.velocity.x = -100;zombie.sprite.body.velocity.y = -100;but the x component seems to be ignored - I think that i because of moveLeft in another part of a update loop. How I suppose to deal with it?
  19. i need to check if there is an object above the player with which i doesn't collide yet (but will collide if he jumps).. so lets say: i want to find out if there is something 40 pixels above my player.. or in other words: ;-) if (isObjectOnPosition(player.y-40)){ wouldcollideifjump = true; } thx
  20. i want to fix the weapon to my player so i did player.addChild(weapon); this is good and fixes the sprite to the player but when i enable the pyhiscs body , disable gravity for the weapon, set it to kinematic and so on - no matter what i do the physics body will stay at it's koordinates... so i did something like weapon.body.x = player.body.x (that fixes the physics body position but then the sprite has a huge offset for some reason.. i want to rotate my weapen so i want the anchor to be at (0.5,1) this works great for the sprite but the body always keeps rotating around 0.5,0.5 (the center) all in all i can say.. nothing works as i want it to work.. please help.. thx!
  21. in my phaser game i found a bug (it is really hard to reproduce and there is no error message in the console when it happens but i manage to hit the bug when i try long enough) where every single sprite in my game world suddenly sits in the upper left corner, unscaled, unrotated, still animated but no physics anymore.. input events come through so my player still makes the jump move for example (but of course doesn't jump) i encountered the very same thing a while ago on a phaser update where i worked with some attributes on objects i created from tiled object layer and those attributes weren't there anymore because of some changes in 2.0.4 (rich made a few changes and since then it works fine) but this time it is differen everything works fine.. until... my player has an anchor with a rope that he can shoot and with this tool hang on every wall - when i shoot the anchor often enough on a sprite (created from an object) i think i need to shoot between the sprite and the tilemap wall (there is no gap but the anchor sometimes slips through a little bit) and bam! everything is mashed together and fixed to the upper left corner.. EDIT: i think one reason why i encountered this bug when shooting the anchor between the sprite and the "thin" wall is that the anchor (maybe) at some point flies through the wall (which is positioned on the very left side of the game world) and then tries to anchor it self outside of the game world ???? (i catch the point where a first shot sensor hits the wall and create a new anchor sprite at the very same point to anchor my rope) EDIT2: i guess not.. i created the wallanchor outside of the world on purpose and couldn't trigger the bug.. i have absolutely NO idea what is happening so i ask here.. maybe someone as an idea... screenshot:
  22. Hey all, Just a quick heads up to share an odd solution to a problem that had me tearing my head out for a couple of days, thought it may come in handy for anyone else in the same boat. While working on a game where I was using P2 physics to detect a collision event between 2 physics bodies, I found that whenever the target sprite was rotated further than a certain amount all of my collision events would silently fail. I spent AGES trying different collision methods and none of them worked, when trying to implement a hack-ish workaround that I found on the forums (can't remember where) I realised that my collisions were now working fine, even though the method I was using returned something to the effect of "this doesn't work". Long story short - I found that by resetting a physics body's AABB data after every change in rotation made the collision events work again: //attackingThing.body.onBeginContact.add(reportSomething, this);//function rotateThing() { // thing.rotation += 1; // reportSomething fails unless you do this thing.body.data.updateAABB();}If anyone can enlighten me as to what/why/how this works, that'd be awesome. Phase on, dudes! OFM
  23. instantia

    Map p2 physic

    How to create it? - red line - polygon. - colorful squares - tile map - random or atlas file. How to set the polygon object I know. Here, too, and plan. How do I randomly impose sprites? What to do to create? To trim down the red line
  24. I turned to reflect sprite. this.obj.scale.setTo(1, -1); How to reflect the polygon body p2 physic? body.setTo(1, -1) not working
  25. How do I desired deceleration of the object in motion? Suppose when the object is in the water acts on it slowing. I tried to do velocity * 0.99. Slowing down there, but got out a lot of bugs. Now do so:this.obj.rotation = game.physics.arcade.moveToXY(this.obj, this.pointer.x, this.pointer.y, this.speed, 200);How do I make braking object? I've already rummaged