我想数一下 Phaser 游戏中我的角色在哪个板块中的编号。?

I want to count Phaser game no of tile my charachter in which tile.?

https://github.com/SafaErden/IcyTower 我的游戏来自这个项目请给我解决方案?

一个快速的解决方案,当出现 platform-collision 时,只需计算分数。

代码中需要的更改是:

文件中GameScene.js:

line 67: 改变

   this.physics.add.collider(this.player, this.platformGroup);

对此:

this.physics.add.collider(this.player, this.platformGroup, (player, platform) =>{
    // just checks if the player is over the platform (can be optimized)
    if(player.y < platform.y){
        // set Score (for the the I just update the Text)
        scoreText.setText(`Score:${platform.name  * 10}`);   
    }
});

line 76: 在这行代码之后添加:

// here I'm using the name property (that is reserved for developers), to keep track of the Platform number
platform.name = gameOptions.platformCounter;

因为gameOptions.platformCounter好像是在游戏的时候加起来的,这个可以用。 (或者您可以创建另一个 属性,用于计算 score/platform)

信息:这样设置分数有魅力,如果用户掉到较低的平台,又会失去分数

旁注:您必须删除 第 125 和 126 行才能正常工作:

    score = updateScore(score);
    scoreText.setText(`Score:${score}`);

话题更新:

万一“想在更新中更改代码”,我会 use/create 属性。例如:如果升级到 100 分,我会将代码更改为:

this.physics.add.collider(this.player, this.platformGroup, (player, platform) =>{
    if(player.y < platform.y){
        // set Score (for the the I just update the Text)
        score = platform.name  * 10
        scoreText.setText(`Score:${score}`);   
    }
});

创建一个全局变量level类似于score:

let level = 0;

以及 update 函数中的某处 (不在 for 循环中),只需添加如下内容:

// Just to be sure that the level count only goes up
if(parseInt(score / 100)> level) { 
    level++;
    // change background / music / ...
}