PrzeGrze Posted July 16, 2020 Share Posted July 16, 2020 Hello, I've been following platformer tutorial so far, and wanted to implement similar stomping behavior to the one on the main page. Once the mainPlayer stomps something, I want the second object to flash for a while and then get removed. I'm using boilerplate 2.3.0 atm and tried to fiddle with me.Timer; onCollision: function (response, other) { if (response.b.body.collisionType !== me.collision.types.WORLD_SHAPE) { // res.y >0 means touched by something on the bottom // which mean at top position for this one if (this.alive && (response.overlapV.y > 0) && response.a.body.falling) { this.renderable.flicker(750); me.timer.setTimeout(me.game.world.removeChild(this), 750) } return false; } // Make all other objects solid return true; } However, enemy entity gets removed directly, and after timeout I face a crash. Seems like the child is undefined in this context. Replacing ```this``` in ```removeChild()``` with ```response.b``` yielded same error. Beats me how to implement stomp mechanic, so I'd like to ask for some pointers and or assistance. Regards Quote Link to comment Share on other sites More sharing options...
obiot Posted July 17, 2020 Share Posted July 17, 2020 flicker actually takes an optional callback function as argument, so you can directly remove the child from there or do whatever else you need when the effect is over. also it's good practice to disable collision on that object at that point, you can do it using setCollisionMask (at least this is how I do it), but using your own variable also do the job see the example below for both : https://github.com/melonjs/melonJS/blob/master/examples/platformer/js/entities/enemies.js#L78-L102 PrzeGrze 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.