朝光标移动
原文地址:http://www.phaser.io/examples/v2/arcade-physics/move-to-pointer。
效果
源代码
window.onload = function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser_container', preload: preload, create: create, render: render }); function preload() { game.load.image('backdrop', 'images/phaser/remember-me.jpg'); game.load.image('ball', 'images/phaser/shinyball.png'); } var ball; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.world.setBounds(0, 0, 1920, 1200); game.add.sprite(0, 0, 'backdrop'); ball = game.add.sprite(game.world.randomX, 200, 'ball'); game.physics.arcade.enable(ball); game.input.onDown.add(moveBall, this); } function moveBall() { game.physics.arcade.moveToPointer(ball, 100); } function render() { game.debug.text("距离: " + game.physics.arcade.distanceToPointer(ball), 32, 32); } }
发布时间:2016/9/22 下午9:31:12 阅读次数:4486