多个sprite朝向光标
原文地址:http://www.phaser.io/examples/v2/arcade-physics/multi-angle-to-pointer。
效果
源代码
window.onload = function () { var game = new Phaser.Game(600, 400, Phaser.AUTO, 'phaser_container', { preload: preload, create: create, update: update }); function preload() { game.load.image('arrow', 'images/phaser/longarrow.png'); } var sprite1; var sprite2; var sprite3; var sprite4; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#363636'; sprite1 = game.add.sprite(150, 150, 'arrow'); sprite1.anchor.setTo(0.1, 0.5); sprite2 = game.add.sprite(200, 300, 'arrow'); sprite2.anchor.setTo(0.1, 0.5); sprite3 = game.add.sprite(400, 200, 'arrow'); sprite3.anchor.setTo(0.1, 0.5); sprite4 = game.add.sprite(500, 300, 'arrow'); sprite4.anchor.setTo(0.1, 0.5); } function update() { // 更新sprite.rotation的值,使之朝向当前的光标(桌面系统是鼠标,移动设备通常是手指按压处) sprite1.rotation = game.physics.arcade.angleToPointer(sprite1); sprite2.rotation = game.physics.arcade.angleToPointer(sprite2); sprite3.rotation = game.physics.arcade.angleToPointer(sprite3); sprite4.rotation = game.physics.arcade.angleToPointer(sprite4); } }
发布时间:2016/8/20 下午4:02:27 阅读次数:4507