To enable keyboard input, you must first initialize and assign it to variables. Mouse input works without assignment, but by changing parameters of individual sprites.

"use strict"; = {
    create: function() {
		//creates sprite and enables mouse input and mouse drag = mt.create("box_simple"); = true;;

        //creates variables, containing the keys
        this.cursors =;
        this.shift =;
        this.ctrl =;

    update: function() {
        //carries out an action, depending on the pressed button, while the button is held down
        if (this.cursors.up.isDown) -= 4;
        if (this.cursors.down.isDown) += 4;
        if (this.cursors.right.isDown) += 4;
        if (this.cursors.left.isDown) -= 4;

        if (this.shift.isDown) += 2;
        if (this.ctrl.isDown) -= 2;

Move the box around, by using the cursor keys or dragging with mouse. Rotate with CTRL and SHIFT.

Full sample available here.

Leave a Reply

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