0

我实际上是在制作 Stardew Valley 克隆,使用瓷砖组和瓷砖层来绘制每个房间的背景。我有一个“父深度对象”。该对象的每个子对象(NPC、作物)的深度相对于玩家对象进行排序,以显示在玩家的前面或后面。这工作正常。

我在每个房间的一个瓷砖层上都有“地面物品”(桶、石头等)。我希望玩家也能够出现在这些东西的后面或前面。有什么方法可以让整个图层看起来像一个单独的对象,这样我就可以将它添加到我的父深度对象中,还是我必须为每个地面项目创建一个单独的对象?

我的“depthSorter”对象创建了一个数据结构,将每个实例添加到其中并循环遍历,对每个相对于玩家的深度进行排序。


/// @description DSGridGetInst/Add/Sort/Loop

// get number of instances of parentDepthObject, save in variable instNum / resize grid
var instNum = instance_number(parentDepthObject);
var dGrid = dsDepthGrid;

ds_grid_resize(dGrid, 2, instNum);

// add instances to grid / have all of them run this code
var yy = 0; with(parentDepthObject)
{
    dGrid[# 0, yy] = id;
    dGrid[# 1, yy] = y;
    yy += 1;
}

// sort the grid in ascending order (lowest y value at top)
ds_grid_sort(dGrid, 1, true);

// loop through the grid and draw all the instances

var inst; yy = 0; repeat(instNum)
{
    // pull out an ID
    inst = dGrid[# 0, yy];
    // draw yourself
    with(inst)
    {
        event_perform(ev_draw, 0);
    }

    yy += 1;
}

4

1 回答 1

0

我个人建议将这些您想要放在后面的物品用作对象,而不是瓷砖。瓦片本身不能包含脚本。因此,以您想要的方式使用它们变得更加棘手。

但是,您不需要为每个“地面项目”创建一个新对象。相反,您可以制作一个名为“地面项目”的对象,并将精灵/相关代码更改为该对象。

例如,在房间中选择一个对象时,您可以使用“创建代码”添加该对象的唯一代码。这样,您可以将地面项目的精灵更改为它的唯一 ID。

另一个例子是创建一个对象,它是父“地面对象”的子对象。所以每个对象都有自己的精灵,但会重用“地面对象”中的对象

于 2020-02-07T15:56:55.987 回答