Game Maker - 并非所有对象都有效

Game Maker - Not all objects work

这是我的代码(放置在步骤事件中)

if (place_meeting(x,y,Obj_Player))
{
    time = 50
}
if (time > 0)
{
    Obj_Player.jsp = 17;
}
else
{
    Obj_Player.jsp = 12;
}
if (time > 0) time -= 1;

放置在创建事件中:

image_speed = 0.4;
time = 0;
new = 17

出于某种原因,具有此代码的一个对象可以工作,但其余的则不能。我不知道为什么,房间里需要多件物品。

另外,创建事件中的项目,我想移动到每个单独项目的创建代码中。我只想编辑 new 所以我必须移动所有代码还是只移动 new?

当您使用Obj_Player.blablabla时,GMS 将获取第一个创建的对象实例。您需要使用 return id 实例的函数。例如,instance_place()。我不确定你到底在做什么,所以代码可能无法使用:

所有实例使用一个全局计时器的示例:

var obj = instance_place(x, y, Obj_Player);
if obj != noone
{
    with Obj_Player
    {
        time = 50;
    }
}

with Obj_Player
{
    if (time > 0) time--;
}

接下来是Obj_Player:

// Create
time = 0;

// Step
if time > 0
    jsp = 17;
else
    jsp = 12;


每个实例都有一个独立的本地计时器的示例:

var obj = instance_place(x, y, Obj_Player);
if obj != noone
    obj.time = 50;

接下来是Obj_Player:

// Create
time = 0;

// Step
if time > 0
    jsp = 17;
else
    jsp = 12;

if (time > 0) time--;

更新:

Just to clarify, I have one Obj_Player and multiple items which contain the code.

我想我明白你想做什么

Obj_Player,创建:

time = 0;

Obj_Player,碰撞事件(与您的对象):

time = 50;

Obj_Player,步骤事件:

time--;
if time > 0
    jsp = 17;
else
    jsp = 12;

就这些了。

如您所见,所有代码都放在Obj_Player。因为当你做

if time > 0
    Obj_Player.jsp = 17;
else
    Obj_Player.jsp = 12;

并且您有多个具有此代码的实例,只有当 所有 个实例都具有 time > 0 时,jsp 才会 17。实际上,jsp 将包含最后一次检查的结果(因为最后一次检查无论如何都会替换任何以前的结果)。




Also, the items in the create event, I would like to move into the creation code of each individual item. I only want to edit new so will I have to move all the code or just new?

只有 new。首先将被称为 Create 事件(如果我们谈论的是 GMS,而不是 GM8)然后是 Creation code,所以使用 Creation code 你可以只修改所有 [=31] 中的内容=] 事件.