【问题标题】:GML: Getting an instance ID from a collision and accessing its variablesGML:从碰撞中获取实例 ID 并访问其变量
【发布时间】:2017-02-08 12:01:39
【问题描述】:

我目前正在gamemaker中制作游戏。玩家攻击的工作原理是让玩家获得耐力并将其存储在一个伤害变量中,然后飞出玩家并击中敌人,从敌人身上获得两倍于伤害变量的生命值。

如果玩家在进行攻击时体力为 45,则 攻击精灵会飞出去,造成45点伤害。击中敌人时 这将对敌人造成 90 点伤害,只剩下 10 点 健康。

问题是游戏似乎不知道哪个攻击精灵击中了敌人,因为您可以执行基本上无限量的攻击,因此不会对敌人施加正确的伤害。

如何获得与敌人相撞的对象的实例 ID,以便我可以使用它来访问伤害变量?

提前致谢

【问题讨论】:

    标签: instances gml game-maker-language


    【解决方案1】:

    我假设您正在使用与敌人的碰撞事件,对吗?在其中,您应该可以使用other。所以,是这样的:

    var instance_id = other.id

    以下是来自 YoYoGames 的更多信息:

    https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/keywords.html

    这是列表中的第二个 :)

    【讨论】:

      【解决方案2】:

      这是 Jeremy ment 的代码示例:

      触发攻击的事件(例如全局鼠标留在玩家对象中):

      var attackInstance = instance_create(x, y, obj_attack); //Create an instance
      attackInstance.damage = 45; //Set the damage of this _instance_ to 45
      attackInstance.speed = 4; //Make it move
      attackInstance.direction = point_direction(x, y, mouse_x, mouse_y); //in the right direction
      

      在与 obj_enemy 中的 obj_attack 发生碰撞事件中:

      hp -= other.attack*2;  //My HP gets down by the amount of the attack variable in the collided instance.
      with(other) {
          instance_destroy(); //Destroy the attack object
      }
      

      这基本上应该可以解决问题:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-26
        • 1970-01-01
        • 1970-01-01
        • 2015-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多