Search the Community
Showing results for tags 'collision callback'.
-
Forewarning: semi-newbie Basically, if the user has the left cursor down and a "token" collides with the lftRect, I want to kill the token. For some reason my kill callback function for the collision is not working (below is relevant code): gumballGoGo.Preloader = function(game){ this.player = null; this.ground = null; //this.tokens = null; this.ready = false; }; var cursors, lftInit, rghtInit, ground, testDrp, sprite, tokens, rect, lftRect, ctrRect, rghtRect, lftToken; var total = 0; function lftHit(lftRect, lftToken) { if ( lftInit == true ){ lftToken.kill() } }; gumballGoGo.Preloader.prototype = { preload: function(){ }, create: function() { // LFT BOX lftRect = this.add.sprite(0, this.world.height - 150, null); this.physics.enable(lftRect, Phaser.Physics.ARCADE); lftRect.body.setSize(100, 100, 0, 0); // CNTR BOX ctrRect = this.add.sprite(100, this.world.height - 150, null); this.physics.enable(ctrRect, Phaser.Physics.ARCADE); ctrRect.body.setSize(100, 100, 0, 0); // RGHT BOX rghtRect = this.add.sprite(200, this.world.height - 150, null); this.physics.enable(rghtRect, Phaser.Physics.ARCADE); rghtRect.body.setSize(100, 100, 0, 0); // INIT TOKEN GROUP tokens = this.add.group(); tokens.enableBody = true; this.physics.arcade.enable(tokens); testDrp = tokens.create(125, -50, 'token'); testDrp.body.gravity.y = 300; // CONTROLS this.cursors = this.input.keyboard.createCursorKeys(); }, update: function() { this.ready = true; if (this.cursors.left.isDown) { lftInit = true; } else if (this.cursors.right.isDown) { rghtInit = true; } else { lftInit, rghtInit = false; } if (total < 20) { tokenSpawn(); } this.physics.arcade.collide(lftRect, lftToken, lftHit, null, this); } }; function tokenSpawn() { lftToken = tokens.create(25, -(Math.random() * 800), 'token'); lftToken.body.gravity.y = 300; total++; } PLEASE HELP! The ultimate goal is to recreate this type of gameplay. One additional note: as of now I am dropping "tokens" using a random spawn loop. I'd rather use a timed patter for the token drop. If you have any advice on that please share as well. Thanks :]
-
I'm trying to get a callback, when the player hits the door, but nothing happens... It drives me crazy now, and I don't know why this doesn't work, cause I think it should. This is what i have under create: //Load player //1700 playerSprite = this.game.add.sprite(50, 900, 'player-front'); player = new Player(playerSprite); //Physics this.game.physics.startSystem(Phaser.Physics.P2JS); //Setting up witch tiles needs colliders map.setCollision(261, true, 'Collisions'); this.game.physics.p2.convertTilemap(map, 'Collisions'); this.game.physics.p2.enable([player.sprite], true); player.sprite.body.fixedRotation = true; //Physics engine create collision bodies from the tiles this.game.physics.arcade.enable(map); this.game.physics.setBoundsToWorld(); this.game.physics.p2.setImpactEvents(true); var playerCollisionGroup = this.game.physics.p2.createCollisionGroup(); var doorCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.game.physics.p2.updateBoundsCollisionGroup(); var doors = this.game.add.group(); doors.enableBody = true; doors.physicsBodyType = Phaser.Physics.P2JS; var door = doors.create(350, 865, 'player-back'); door.body.setRectangle(40,60,0,0); door.body.debug = true; door.body.setCollisionGroup(doorCollisionGroup); door.body.collides(playerCollisionGroup); player.sprite.body.setCollisionGroup(playerCollisionGroup); player.sprite.body.collides(doorCollisionGroup, this.hitDoor); And this is my hitDoor function: hitDoor: function(body1, body2){ console.log("Does this work??"); }, What am I doing wrong? Ty.
- 1 reply
-
- collision callback
- javascript
-
(and 1 more)
Tagged with:
-
I'm doing a platformer and I want to have breakable tiles. When the player touches the tile, the tile disappears( and the empty space stops colliding). In phaser one I could set up a tile index callback which would set the tile index to 0 and recalculate collision, but in phaser 2 this doesn't seem to be possible. Is there any way to remove a tile object from a tilemap layer? I can't find it in the docs.