朝光标移动

原文地址: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

2006 - 2024,推荐分辨率 1024*768 以上,推荐浏览器 Chrome、Edge 等现代浏览器,截止 2021 年 12 月 5 日的访问次数:1872 万 9823 站长邮箱

沪 ICP 备 18037240 号-1

沪公网安备 31011002002865 号