GUI 仅适用于最新的塔,我不知道为什么。 (游戏制作人)

问题描述 投票:0回答:1

我在游戏中遇到问题。当我在一个地方制作第一个塔时,GUI 工作正常,但是当我放置第二个塔时,GUI 仅适用于第二个塔,并且它会一直持续到我所在的每个最新塔。 步骤:

if placed != false
{
    image_alpha = 1;
    
if collision_circle(x,y,200,oEnemy,false,true)
{
if instance_exists(oEnemy)
{
target = instance_nearest(x,y,oEnemy)
        if target.x < x
        {
            direction = point_direction(x-18,y,target.x,target.y);
        }
        else
        {
            direction = point_direction(x+18,y,target.x,target.y);
        }
        if alarm[0] = -1
{
    alarm[0] = 60;
}
    }
}

if mouse_check_button(mb_any)
{
    if !position_meeting(mouse_x,mouse_y,self)
    {
    GuiOpen = false;
    }
    else
    {
    GuiOpen = true
    }
}

}
else
{
    x = mouse_x;
    y = mouse_y;
    image_alpha = 0.5;
}

if GuiOpen = true
{
    instance_create_layer(x,y-65,"Instances2",o_Tower1Upgrade);
}
else
{
    instance_destroy(o_Tower1Upgrade);
    instance_destroy(o_tower1upgradebutton1);
}

我尽力找出错误,但我真的不能,输出中没有错误,也没有任何我能发现的代码错误。

game-maker game-maker-studio-2 game-maker-language
1个回答
0
投票

您可能想尝试

position_meeting
,而不是
instance_position
。 这样做的原因是因为“_meeting”意味着该类型的任何对象都将履行其角色,而不是您想要获取的特定对象。

来源:https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Asset_Management/Instances/instance_position.htm

我的这一点是基于我与

place_meeting
instance_place
的类似经历。问题和解决方案看起来非常相似: https://gamedev.stackexchange.com/questions/158359/when-there-are-multiple-objects-of-the-same-type-how-do-i-know-which-one-i-am-c

© www.soinside.com 2019 - 2024. All rights reserved.