var game =newPhaser.Game(800,600, Phaser.AUTO,'phaser-example',{ preload: preload, create: create, update: update });functionpreload(){
game.load.image('ball','assets/sprites/shinyball.png');}var sprite;functioncreate(){
sprite = game.add.sprite(game.world.centerX, game.world.centerY,'ball');
game.physics.enable(sprite, Phaser.Physics.ARCADE);}functionupdate(){// only move when you clickif(game.input.mousePointer.isDown){// 400 is the speed it will move towards the mouse
game.physics.arcade.moveToPointer(sprite,400);// if it's overlapping the mouse, don't move any moreif(Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y)){
sprite.body.velocity.setTo(0,0);}}else{
sprite.body.velocity.setTo(0,0);}}