具有重力效果的反弹
原文地址:http://www.phaser.io/examples/v2/arcade-physics/bounce-with-gravity。
效果
源代码
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('flyer', 'images/phaser/phaser-dude.png');
}
var image;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
image = game.add.sprite(300, 200, 'flyer');
game.physics.enable(image, Phaser.Physics.ARCADE);
// 设置初速度
image.body.velocity.setTo(200, 200);
// 世界边界反弹
image.body.collideWorldBounds = true;
// 碰撞后损失一定的速度
image.body.bounce.set(0.8);
// 设置重力
image.body.gravity.set(0, 180);
}
function update() {
// 不需要
}
function render() {
game.debug.spriteInfo(image, 32, 32);
}
}
发布时间:2016/8/31 下午9:17:05 阅读次数:5549
