alriano Posted September 22, 2013 Share Posted September 22, 2013 can someone give me a good example to do this?for example, if player collide with lava tiles then kill the player Link to comment Share on other sites More sharing options...
rich Posted September 22, 2013 Share Posted September 22, 2013 I'll prepare an example showing this tonight, but basically you use a custom collision callback and then compare the sprite with the tile (game.physics.collide(player, map, callback, null, this) Link to comment Share on other sites More sharing options...
Straker Posted September 28, 2013 Share Posted September 28, 2013 What is commonly done is that a 2nd tilemap is created whose sole purpose is to deal with collisions. This collision tilemap just holds information about where collisions will occur and what type of tile the collision is. Then when you move the player, you just check where the player is going against the collision tilemap and if the tile the player is moving into has a tile, you can check what type of tile and respond accordingly. So for example, let's say you have a room surrounded by walls (represented by tile #1) with a river of lava through it (represented by tile #2) and any tile that doesn't have a collision will be empty (represented by tile #0). The collision tilemap could look like the following: <code>collisionTilemap = [ [1, 1, 1, 1, 2, 1, 1, 1, 1], [1, 0, 0, 0, 2, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 2, 0, 0, 0, 1], [1, 1, 1, 1, 2, 1, 1, 1, 1]]</code> When the player tries to move into a tile with the #1, he is just prevented from moving into the square. But if the player tries to move into a tile with the #2, the player dies because he touched lava. Bonsaiheldin, plicatibu and Aicha 3 Link to comment Share on other sites More sharing options...
xronn Posted February 5, 2014 Share Posted February 5, 2014 Rich did you ever make an example showing the interaction between a player, and a tileset in these events? Link to comment Share on other sites More sharing options...
rich Posted February 5, 2014 Share Posted February 5, 2014 Yes there is an example in the tilemaps section showing collision against a specific tile ID with a custom callback. Link to comment Share on other sites More sharing options...
GNUton Posted March 11, 2014 Share Posted March 11, 2014 Just for reference the example can be found at this address: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=tile+callbacks.js&t=tile%20callbacks Ansimuz 1 Link to comment Share on other sites More sharing options...
beancoder Posted July 25, 2014 Share Posted July 25, 2014 Hi,I just want to ask something. I have made a game where I have used canvas to make a string. Basically the canvas is a line which behaves as a string. So what I want to do is detect when the string(i.e. canvas) collides with coin tiles on the tilemap. how can I use game physics and collide functions between canvas and a tilemap layer? (Not a sprite and tilemap). Please help. Link to comment Share on other sites More sharing options...
jmp909 Posted October 4, 2015 Share Posted October 4, 2015 I would put invisible physics objects over the string portions, ie some small rectangles i don't know whether rope helps, but press 'D' and that's kind of similar to what i meant, just biggerhttp://phaser.io/examples/v2/sprites/rope Link to comment Share on other sites More sharing options...
symof Posted August 16, 2016 Share Posted August 16, 2016 Sorry to revive this but I'm having some problems with this example here. http://phaser.io/examples/v2/tilemaps/tile-callbacks My main issue is that on collision the tile becomes passable. How do I make it impassable? In the example, the once the arrow connects with the coin, then the coin changes it alpha value AND becomes passable at the same time. Why? How do I make it so that I can get the collide callback but not change any physics? EDIT: // This will set Tile ID 26 (the coin) to call the hitCoin function when collided with map.setTileIndexCallback(26, hitCoin, this); // This will set the map location 2, 0 to call the function map.setTileLocationCallback(2, 0, 1, 1, hitCoin, this); These 2 functions here for example. the .setTileLocationCallback works as how I imagine it. It sets the tiles.alpha to 0.2 but it's not passable by the sprite body. Meanwhile the setTileIndexCallback makes it both passable and adds alpha to it. Why does one change the physics and the other one does not? I would prefer if neither changed the physics, the way setTileLocationCallback is set up. EDIT 2: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=tile+callbacks.js&t=tile callbacks And in this example both functions make the tile passable. Link to comment Share on other sites More sharing options...
anthkris Posted August 24, 2016 Share Posted August 24, 2016 Wanted to make sure I posted this @symof. I submitted an issue and got some answers. You need to return true in the callback function to keep the tile impassable. Bonsaiheldin and symof 2 Link to comment Share on other sites More sharing options...
symof Posted August 24, 2016 Share Posted August 24, 2016 2 hours ago, anthkris said: Wanted to make sure I posted this @symof. I submitted an issue and got some answers. You need to return true in the callback function to keep the tile impassable. Thanks for your reply. I did change the return value to true in the hitCoin function from the example and it's still passable. http://phaser.io/sandbox/edit/WDmKTvNO You can see from the example that the coin is not impassable even with hitCoin returning true. Link to comment Share on other sites More sharing options...
anthkris Posted August 24, 2016 Share Posted August 24, 2016 In that example, collision had not been set previously on that tile. If you change the map collision statement thusly: map.setCollisionBetween(1, 26); Then, you will collide with the coin, the alpha will change, but you will not pass through. Bonsaiheldin and symof 2 Link to comment Share on other sites More sharing options...
symof Posted August 24, 2016 Share Posted August 24, 2016 Thanks. I forgot to check if the tile collision is set up. Link to comment Share on other sites More sharing options...
Recommended Posts