Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Existing Layers

A topic by dreamsknight created 53 days ago Views: 54 Replies: 6
Viewing posts 1 to 5

Hello, how do I make it so that it uses existing layers instead of creating a new one?

function __roomloader_create_layer(_data) {

    var _existing_layer = layer_get_id(_data.name);

var _layer = _existing_layer > -1 ? _existing_layer :  layer_create(_data.depth, _data.name);

layer_set_visible(_layer, _data.visible);

layer_x(_layer, _data.xoffset);

layer_y(_layer, _data.yoffset);

layer_hspeed(_layer, _data.hspeed);

layer_vspeed(_layer, _data.vspeed);

return _layer;

}


I modified this function like this but doesn't seem to work, thanks

Developer (1 edit)

Hey! This is something I'm planning to support officially as soon as I can, but for now there's no one-line fix that would work for all layer types.

Could you explain your exact use case? I might be able to help you get around this.

Thanks for the reply, glad to hear that it's planned! 

I have many layers in my game (150+) , and layers I need to load from another room have varrying depths, I don't wanna set the depth of the layers in external rooms as it will make it hard to make changes. IE if I add a new layer into my main room, now depth changes for all layers and I need to change it in all rooms etc. I also have code that operates on the layer names directly.

Developer

I see. I guess for now you could grab the loaded layer ids from the returned data, change their depths and do whatever else is needed.

I've decided code my own small library since I just need basic functionallity and only instance,asset and background layers. Seems to be working fine so far, but you have helped a lot with your implementation so thanks a lot!

Developer

You're welcome! And cool, hope it works well for you!

Thanks a lot!