forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollow mouse.js
More file actions
37 lines (25 loc) · 819 Bytes
/
Copy pathfollow mouse.js
File metadata and controls
37 lines (25 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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');
}
function update() {
// only move when you click
if (game.input.mousePointer.isDown)
{
// 400 is the speed it will move towards the mouse
game.physics.moveToPointer(sprite, 400);
// if it's overlapping the mouse, don't move any more
if (Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y))
{
sprite.body.velocity.setTo(0, 0);
}
}
else
{
sprite.body.velocity.setTo(0, 0);
}
}