显示轨迹
原文地址:http://www.phaser.io/examples/v2/arcade-physics/ship-trail。
效果
源代码
window.onload = function () { var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser_container', preload: preload, create: create, update: update ,render:render }); function preload() { game.load.image('chunk', 'images/phaser/chunk.png'); game.load.image('arrow', 'images/phaser/asteroids_ship.png'); } var sprite; var bmd; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); // 点击游戏屏幕的左边或右边,可以控制飞船的发射方向 game.stage.backgroundColor = '#124184'; bmd = game.add.bitmapData(800, 600); bmd.context.fillStyle = '#ffffff'; var bg = game.add.sprite(0, 0, bmd); game.physics.arcade.gravity.y = 100; sprite = game.add.sprite(32, 450, 'arrow'); sprite.anchor.set(0.5); game.physics.enable(sprite, Phaser.Physics.ARCADE); sprite.body.collideWorldBounds = true; sprite.body.bounce.set(0.8); game.input.onDown.add(launch, this); } function launch() { if (game.input.x < sprite.x) { sprite.body.velocity.setTo(-200, -200); } else { sprite.body.velocity.setTo(200, -200); } } function update() { sprite.rotation = sprite.body.angle; bmd.context.fillRect(sprite.x, sprite.y, 2, 2); bmd.dirty = true; } function render() { game.debug.bodyInfo(sprite, 32, 32); } }
发布时间:2016/10/11 下午9:40:59 阅读次数:4734