朝向光标
原文地址:http://www.phaser.io/examples/v2/arcade-physics/angle-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', 'assets/sprites/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); } function update() { // 更新sprite.rotation的值,使之朝向当前的光标(桌面系统是鼠标,移动设备通常是手指按压处) sprite.rotation = game.physics.arcade.angleToPointer(sprite); } function render() { game.debug.spriteInfo(sprite, 32, 32); } }
发布时间:2016/8/19 下午8:27:12 阅读次数:4904