JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.3.0/phaser.min.js"></script>
JavaScript
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('arrow', './img/arrow.png');
game.load.image('poo', './img/poo.png');
}
var fly;
var poo;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
poo = game.add.sprite(game.input.mousePointer.x, game.input.mousePointer.y, 'poo');
poo.anchor.setTo(0.5, 0.5);
game.input.addMoveCallback(move, this);
game.physics.enable(poo, Phaser.Physics.ARCADE);
game.stage.backgroundColor = '#0072bc';
fly = game.add.sprite(400, 300, 'arrow');
fly.anchor.setTo(1, 0.5);
// Enable Arcade Physics for the sprite
game.physics.enable(fly, Phaser.Physics.ARCADE);
// Tell it we don't want physics to manage the rotation
fly.body.allowRotation = false;
}
function move(pointer, x, y) {
poo.x += game.input.mouse.event.webkitMovementX;
poo.y += game.input.mouse.event.webkitMovementY;
}
function update() {
game.physics.arcade.overlap(fly, poo, decayPoo, null, this);
fly.rotation = game.physics.arcade.moveToPointer(fly, 60, game.input.activePointer, 100);
}
function decayPoo (obj1, obj2) {
game.stage.backgroundColor = '#992d2d';
}
function render() {
game.debug.spriteInfo(fly, 32, 32);
}