praine Posted January 30, 2017 Share Posted January 30, 2017 Hi all, I'm making a Maio-esque platformer, and I'm trying to figure out how to make a tile "bounce" (a bit like the attached GIF, but ideally when hit from below rather than from above) If there are any built in functions or plugins to achieve the desired effect, I would very much appreciate the info. Best, Paul Link to comment Share on other sites More sharing options...
praine Posted January 30, 2017 Author Share Posted January 30, 2017 Hi all, I've implemented a working solution, but not sure if it's the best way to do it. When a collision is detected with the applicable tile, it is removed, and then a sprite with the exact same image is placed in the exact same position. I then use a tween to create the bounce effect, before removing the sprite and replacing the tile again. The code looks like this: hitbox:function(sprite,tile){ if(sprite.body.blocked.up){ if(tile.index==23){ pf.sfx.sounds['box'].play(); pf.map.removeTile(tile.x,tile.y,pf.boxes); var box = pf.game.add.sprite(tile.worldX, tile.worldY, 'tiles'); box.frame=22; // properties, duration, ease, autoStart, delay, repeat, yoyo var bounce=pf.game.add.tween(box).to( { y: box.y-50 }, 100, Phaser.Easing.Linear.InOut, true, 0, false, false).to( { y: box.y }, 100, Phaser.Easing.Linear.InOut, true, 0, false, false); bounce.onComplete.add(function(){ box.destroy(); pf.map.putTile(12, tile.x, tile.y, pf.boxes); }, this) } } }, Resulting animation: Link to comment Share on other sites More sharing options...
Recommended Posts