Skip to content

Instantly share code, notes, and snippets.

@photonstorm
Created August 12, 2014 16:30
Show Gist options
  • Select an option

  • Save photonstorm/9d92f19507df7462ddd5 to your computer and use it in GitHub Desktop.

Select an option

Save photonstorm/9d92f19507df7462ddd5 to your computer and use it in GitHub Desktop.

Revisions

  1. photonstorm created this gist Aug 12, 2014.
    37 changes: 37 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@

    var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });

    function preload() {

    game.load.image('ball', 'assets/sprites/shinyball.png');

    }

    var sprite;

    function create() {

    sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'ball');

    game.canvas.addEventListener('mousedown', requestLock);

    game.input.addMoveCallback(move, this);

    }

    function requestLock() {
    game.input.mouse.requestPointerLock();
    }

    function move(pointer, x, y) {

    if (game.input.mouse.locked)
    {
    sprite.x += game.input.mouse.event.webkitMovementX;
    sprite.y += game.input.mouse.event.webkitMovementY;
    }

    }

    function update() {
    }