Scalemail Ted Posted May 5, 2018 Share Posted May 5, 2018 (edited) I'm attempting to learn Phaser 3 by building a very simple Platformer game. The game is tile based, such that all of my tiles are 32 pixel by 32 pixel. The initial state of my scene is loaded from a 2d array, that I parse into the level during the create phase. My issue is that my hazard tiles, (floor spikes and ceiling spikes) should have collisions only on the bottom half or top half of the sprite. Is there as way to modify the default hitbox of a sprite and redefine it to only be half the height from either the bottom-to-center or top-to-center? Edited May 5, 2018 by Scalemail Ted typo Link to comment Share on other sites More sharing options...
Scalemail Ted Posted May 5, 2018 Author Share Posted May 5, 2018 (edited) I found a solution that works, but it is NOT the most elegant of solutions. Here is my current level parsing function, which works for half collisions on floor-spikes and ceiling-spikes: setTile(x, y, tileID){ if (tileID == "#" ){ this.platforms.create(x*32 + 16, y*32 + 16, 'brick'); } else if (tileID == "@" ) { this.player = this.physics.add.sprite(x*32+16, y*32+2, 'hero'); this.player.setCollideWorldBounds(true); } else if (tileID == "A" ){ let spike = this.hazards.create(x*32+16, y*32+16, 'spike-floor'); spike.body.height = 16; spike.body.customSeparateY = true; spike.body.y += 16; } else if (tileID == "V" ) { let spike = this.hazards.create(x*32+16, y*32+16, 'spike-ceiling'); spike.body.height = 16; } } Is there a cleaner way of achieving/expressing the same functionality? Edited May 5, 2018 by Scalemail Ted tab spacing was off in sample code Link to comment Share on other sites More sharing options...
Recommended Posts