To check for collision between two objects, you must first enable physics on both of them.

Then, in the source editor, we add collision check and keyboard controls to the box object:

"use strict"; = {
    create: function() {
        this.grass = mt.create("grass"); = mt.create("box_simple");

        //initializes the cursor keys
        this.cursors =;

    update: function() {
        //changes the physics body velocity, depending on the key pressed; basic movement controls
        if (this.cursors.up.isDown) = -150;
        else if (this.cursors.down.isDown) = 150;
        else = 0;

        if (this.cursors.right.isDown) = 150;
        else if (this.cursors.left.isDown) = -150;
        else = 0;

        //collision check between two sprites
        //the game checks for collision ONLY between these two sprites
        //can also check between sprite vs group and group vs group,;


Full sample available here.

One thought on “Collision

Leave a Reply

Your email address will not be published. Required fields are marked *