Files
phaser/examples/physics/group move towards object.php
T
Richard Davey 480d90b009 * Removed the callbackContext parameter from Group.callAll because it's no longer needed.
* Updated Group.forEach, forEachAlive and forEachDead so you can now pass as many parameters as you want, which will all be given to the callback after the child.
* Updated build script so it can be run from the command-line and includes UMD wrappers (thanks iaincarsberg)
2013-10-01 02:19:08 +01:00

53 lines
1004 B
PHP

<?php
$title = "Group move towards object";
require('../head.php');
?>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { 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.moveTowardsMouse, game.physics, false, 200);
}
else
{
balls.setAll('body.velocity.x', 0);
balls.setAll('body.velocity.y', 0);
}
}
})();
</script>
<?php
require('../foot.php');
?>