对于大学,我必须创建一个游戏,我的游戏涉及坠落物体。但是我不知道当物体越界时如何失去生命。
这是我的一些代码:
//my variables
var player;
var lives;
var max_lives = 3;
var objects;
var totalLife
var lifeText;
var totalScore;
var scoreText;
var inputs;
//creates the group for the objects
objects = this.add.group();
this.physics.enable(objects, Phaser.Physics.ARCADE);
objects.setAll('outOfBoundsKill', true);
objects.setAll('checkWorldBounds', true);
//spawns object
spawnObject: function () {
var random = this.rnd.integerInRange(0, 25);
if (random === 0) {
var randomX = this.rnd.integerInRange(0, this.world.width - 150);
var object = objects.create(randomX, -50, 'object');
this.physics.enable(object, Phaser.Physics.ARCADE);
object.body.velocity.y = this.rnd.integerInRange(200, 300);
}
}