繁体   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