【发布时间】:2017-09-18 05:30:40
【问题描述】:
我正在尝试检查一个精灵是否正在通过其他两个精灵之间的线。我试图检查精灵是否与 Phaser.Line 重叠:
this.lineGreenToRed = new Phaser.Line(this.ballGreen.x, this.ballGreen.y, this.ballRed.x, this.ballRed.y);
this.checkPassed = this.lineGreenToRed.pointOnLine(this.ballBlue.position.x, this.ballBlue.position.y);
if (this.checkPassed) {
console.log('GreenToRed passed');
//counter++;
};
console.log(this.checkPassed);
只要我的精灵不在/越线,查看控制台就会计算错误事件。有时将它移过界限会给我真实的事件,但并非总是如此。看起来帧变化太快而无法检测到。似乎也不可能对 Lines 进行重叠检查。
我也尝试过:
this.GreenToRedArray = this.lineGreenToRed.coordinatesOnLine();
在更新()中:
this.GreenToRedArray.forEach(this.checkPoint, this);
然后:
checkPoint : function(element){
if (this.ballBlue.position.x == element[0] && this.ballBlue.position.y == element[1]){
console.log('GreenToRed passed');
this.score++;
console.log(this.score);
this.scoreText.setText(this.score);
}
},
只要我在这条线上移动得很慢,这就会起作用,但只要东西移动得快一点,它就不再捕捉它了。
关于如何检查一个精灵是否在其他两个精灵之间的线上移动的任何提示?
把它想象成两个球标志着一个目标,第三个球在这两个球之间射门。
非常感谢您的帮助。
【问题讨论】:
标签: phaser-framework