一组朝指定对象移动
原文地址:http://www.phaser.io/examples/v2/arcade-physics/move-towards-object。
效果
源代码
window.onload = function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser_container', preload: preload, create: create, update: update }); function preload() { game.load.image('ball', 'images/phaser/shinyball.png'); } var balls; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); balls = game.add.group(); balls.enableBody = true; for (var i = 0; i < 50; i++) { var ball = balls.create(game.world.randomX, game.world.randomY, 'ball'); } } function update() { if (game.input.mousePointer.isDown) { // 第一个参数是回调函数 // 第二个参数是回调函数对应的上下文,本例中是game.physics.arcade balls.forEach(game.physics.arcade.moveToPointer, game.physics.arcade, false, 200); } else { balls.setAll('body.velocity.x', 0); balls.setAll('body.velocity.y', 0); } } }
发布时间:2016/9/20 下午9:09:13 阅读次数:4723