跟随光标
原文地址:http://www.phaser.io/examples/v2/arcade-physics/accelerate-to-pointer。
效果
源代码
window.onload = function () { var game = new Phaser.Game(600, 400, Phaser.AUTO, 'phaser_container', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('arrow', 'images/phaser/arrow.png'); } var sprite; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#0072bc'; sprite = game.add.sprite(400, 300, 'arrow'); sprite.anchor.setTo(0.5, 0.5); // 对箭头开启Arcade物理系统 game.physics.enable(sprite, Phaser.Physics.ARCADE); // 物理系统不处理箭头body的旋转 sprite.body.allowRotation = false; } function update() { sprite.rotation = game.physics.arcade.moveToPointer(sprite, 60, game.input.activePointer, 500); } function render() { game.debug.spriteInfo(sprite, 32, 32); } }
发布时间:2016/8/16 下午9:08:06 阅读次数:4892