D3thy Posted May 22, 2014 Share Posted May 22, 2014 Dear Phaser Community, Thanks for taking the time help out. I'm currently trying to kill my player when he touches some fire. The player is just an individual sprite and the fire is my second layer from a tilemap. The idea was to check for collision and then restart game if true. What is the best method to go about doing this, i seem to be unable to figure it out from the collision examples provided by Phaser. preload: //the playergame.load.spritesheet('mainCharacter', 'assets/Game-Graphics/player2.png', 25, 25);//the tilemapgame.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);//the firegame.load.image('doom-fire-tile', 'assets/Game-Graphics/doom-fire.png'); create: //the mapmap = game.add.tilemap('map');//the tilesetmap.addTilesetImage('doom-fire', 'doom-fire-tile');//the layerlayer2 = map.createLayer('killfire') What would be the best method to check for collision between player and the fire or layer 2, and then have the game restart. I'm only using the generic game states so i thought i could just have the restart function reload the "preload state" like this, but it didn't seem to work. function restart(){ game.state.start('preload') } Link to comment Share on other sites More sharing options...
lokhmakov Posted May 22, 2014 Share Posted May 22, 2014 1. Check overlapping in update function, like in example Overlap Without Physicsfunction checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB);} Link to comment Share on other sites More sharing options...
D3thy Posted May 23, 2014 Author Share Posted May 23, 2014 1. Check overlapping in update function, like in example Overlap Without Physicsfunction checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB);} Like i already said in my first post "i seem to be unable to figure it out from the collision examples provided by Phaser." I have already attempted to check for collision and then run my restart function, was unable to make it work. Hence why i am providing the code used to create my objects i want to check collision on, and my restart function to make sure that isn't the problem. Link to comment Share on other sites More sharing options...
Recommended Posts