iffy Posted October 31, 2015 Share Posted October 31, 2015 I have a tilemap with several layers (I made it with Tiled). For some of the tiles, I want the bounding box to enclose only a portion of the tile (e.g. the bottom half). How do I achieve this? For my sprites I use body.setSize: game.physics.arcade.enable(p); p.body.collideWorldBounds = true; p.body.setSize(16, 10, 0, 12);And right now for my map, I have this: layer3 = map.createLayer('blocked'); map.setCollisionBetween(1, 1025, true, 'blocked'); Link to comment Share on other sites More sharing options...
jmp909 Posted November 1, 2015 Share Posted November 1, 2015 not sure about arcade. i use P2 and this is slightly more complicated if you are optimizing the tiles as it groups connected tiles into 1 body (eg my platform is a left, middle and end tile but optimizing will just create one single rectangle for the platform) however if you are not optimizing you can do this (TypeScript)//tiles are 32x32map.setCollisionBetween(1,300, true, 'Layer2')var tileObjects:Phaser.Physics.P2.Body[] = this.game.physics.p2.convertTilemap(map, this.layer2 ,true,false) // <= optimize=falsetileObjects.forEach(function(tile:Phaser.Physics.P2.Body) { tile.clearShapes(); // get rid of the original collision tile.addRectangle(32,16,16,6) // create a new 32x16 physics body (half height of tile) and set relevant offsets to position properly tile.debug=true; tile.setCollisionGroup(tileCollisionGroup) tile.collides(playerCollisionGroup)}, this)I'll have a look into arcade version but I'm assuming it just uses coordinate checks, so you might be stuck there Link to comment Share on other sites More sharing options...
jmp909 Posted November 1, 2015 Share Posted November 1, 2015 for arcade it appears you can do this.. however the debug view does not update and i'm not sure changing tile.centerX, tile.centerY makes any difference.. but for platforms you can achieve similar to above it seemsthis.layer2 = map.createLayer('Layer2')var tiles = this.layer2.getTiles(0,0,this.map.width*32, this.map.height*32)tiles.forEach(function(tile) { if(tile.index!=-1) { console.log("tile", tile) tile.height=12 // you could change this based on tile.index } })this.layer2.debug=true // does not show new collision heights I can't guarantee it won't break anything though.. Link to comment Share on other sites More sharing options...
jmp909 Posted November 1, 2015 Share Posted November 1, 2015 these are all trial and error experiments, but I've also found you can set eg tile.worldY = tile.worldY+8 to shift the collision body down (again doesn't show in debug) without shifting the tile image itself but again beware it might likely break calculations like map.getTileWorldXY.. you'd have to check those sort of things yourself Link to comment Share on other sites More sharing options...
Recommended Posts