Jump to content

Stomp mechanic on collision


Recommended Posts


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) {
                    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.


Link to comment
Share on other sites

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 :



Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...