Body移动
原文地址:http://www.phaser.io/examples/v2/arcade-physics/direct-body-movement。
效果
源代码
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('atari', 'images/phaser/atari130xe.png'); game.load.image('mushroom', 'images/phaser/mushroom2.png'); } var sprite1; var sprite2; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#2d2d2d'; sprite1 = game.add.sprite(200, 50, 'atari'); sprite2 = game.add.sprite(300, 250, 'mushroom'); game.physics.arcade.enable([sprite1, sprite2], Phaser.Physics.ARCADE); game.add.tween(sprite1.body).to({ y: 400 }, 3000, Phaser.Easing.Linear.None, true); } function update() { // 如果两张图像重叠则改变背景颜色 game.physics.arcade.overlap(sprite1, sprite2, overlapHandler, null, this); } function overlapHandler(obj1, obj2) { game.stage.backgroundColor = '#992d2d'; obj2.kill(); } function render() { game.debug.body(sprite1); game.debug.body(sprite2); } }
发布时间:2016/9/2 下午9:38:20 阅读次数:4850