forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove towards object.js
More file actions
37 lines (26 loc) · 893 Bytes
/
Copy pathmove towards object.js
File metadata and controls
37 lines (26 loc) · 893 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 balls;
function create() {
balls = game.add.group();
for (var i = 0; i < 50; i++)
{
balls.create(game.world.randomX, game.world.randomY, 'ball');
}
}
function update() {
if (game.input.mousePointer.isDown)
{
// First is the callback
// Second is the context in which the callback runs, in this case game.physics
// Third is the parameter the callback expects - it is always sent the Group child as the first parameter
balls.forEach(game.physics.moveToPointer, game.physics, false, 200);
}
else
{
balls.setAll('body.velocity.x', 0);
balls.setAll('body.velocity.y', 0);
}
}