2014-05-13 2 views
0

대학 용 게임을 만들어야하는데, 내 게임에는 떨어지는 물체가 포함됩니다. 하지만 내가 어떻게 인생을 잃을 알아낼 수 없다 때 개체가 경계 밖으로 간다.페이저 2 스프라이트 경계를 감지합니까?

내 코드의 Heres는 몇 가지 : 그들은 세계의 경계를 떠날 때

//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); 
    } 
} 

답변

4

스프라이트가 이벤트를 발생. 그것이 하나의 삶을 버리는 것을 들어라.

sprite.checkWorldBounds = true; 

그런 다음, 당신이들을 수 있습니다 :

sprite.events.onOutOfBounds 

을 ... 한 생활을 포기하여 반응

이벤트가 사용 방출되는 사용합니다.

관련 문제