query(opt: QueryOpt): GameObj[]

Get a list of game objects in an advanced way.

paramopt- The query options.

const bean = k.add(["friend", "bean"]);
const bean2 = k.add(["friend", "bean"]);
const bag = k.add(["friend", "bag"]);

// get bean
query({
    include: "bean",
}) // will return [bean, bean2];

// get all friends excluding bean
query({
    include: "friend",
    exclude: "bean",
}); // will return [bag]

// get all visible friends
query({
    include: "friend",
    visible: true,
});

// get all friends less than 150 pixels from bean
bean.query({
    include: "friend",
    distance: 150,
});

kaplay logo

Misc

Layer