mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
* 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)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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');
|
||||
?>
|
||||
Reference in New Issue
Block a user