簡體   English   中英

Phaser3:如何與組中的單個成員做出反應

[英]Phaser3: How to react with a single member of a group

我有一堆雪人。 他們都是補間。 當玩家被特定的雪人捕獲時,它會被它攜帶。

創建每一個精靈並將其設置為補間是混亂、不方便和浪費時間的。 我已經學會使用

常量雪人 = this.physics.add.group(); 雪人.create(x, y, 'key');

但這並沒有給每個雪人一個名字。 當我設置玩家被攜帶時的 X 和 Y 時,我將它設置為擊中他的雪人的 x 和 y。 如果我使用上面的代碼,它顯然將不再工作。 可以做些什么呢?

在此處輸入圖像描述

非常感謝。 (來自初學者)

好吧,不知道你的代碼。 我會:

  • 創建一個變量來標記具有玩家的雪人
  • 當玩家與一個雪人碰撞時,設置變量。 這樣你就知道是哪個雪人了。

create function 中:

function create(){

    ...
    this.mainSnowMan = undefined; // at the begining no snowman is selected
    this.physics.add.collider(player, snowman, (player, currentsnowman) => {
        ...
        this.mainSnowMan = currentsnowman; // set the snowman that collided with the player
    });
    ...
}

documenation to the collider function https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Collider.html

這是一個鏈接,所以 man 移相器物理示例: https://phaser.io/examples/v3/category/physics/arcade

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM