两物体间的角度
原文地址:http://www.phaser.io/examples/v2/arcade-physics/angle-between。
效果
源代码
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/longarrow.png'); game.load.image('ball', 'images/phaser/pangball.png'); } var arrow; var target; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#0072bc'; arrow = game.add.sprite(200, 250, 'arrow'); arrow.anchor.setTo(0.1, 0.5); target = game.add.sprite(400, 300, 'ball'); target.anchor.setTo(0.5, 0.5); target.inputEnabled = true; target.input.enableDrag(true); } function update() { arrow.rotation = game.physics.arcade.angleBetween(arrow, target); } function render() { game.debug.text("拖动球", 32, 32); game.debug.spriteInfo(arrow, 32, 100); } }
解释
angleBetween(source, target, world) → {number}
获取两个显示对象之间的角度(单位为弧度)。可选参数world
返回的是基于Game Object的world属性的结果,若没有这个参数,则返回常规的x和y值。
发布时间:2016/8/17 下午9:58:13 阅读次数:4567