Body调试
原文地址:http://www.phaser.io/examples/v2/arcade-physics/body-debug。
效果
源代码
window.onload = function () { var game = new Phaser.Game(600, 400, Phaser.AUTO, 'phaser_container', { preload: preload, create: create, render: render }); function preload() { game.load.image('atari', 'images/phaser/atari130xe.png'); } var sprite; var showDebug = true; function create() { game.stage.backgroundColor = '#2d2d2d'; game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 100; sprite = game.add.sprite(150, 100, 'atari'); game.physics.arcade.enable(sprite); sprite.body.velocity.set(-100, -100); sprite.body.bounce.set(1); sprite.body.collideWorldBounds = true; game.input.onDown.add(toggle, this); } // 点击鼠标可以显示\隐藏调试信息 function toggle() { showDebug = (showDebug) ? false : true; if (!showDebug) { game.debug.reset(); } } function render() { if (showDebug) { game.debug.bodyInfo(sprite, 32, 32); game.debug.body(sprite); } } }
发布时间:2016/8/29 上午11:13:42 阅读次数:4432