layer_sprite_at(layer_id, x, y)

Kezarus

Member
Hi!


Pretty straight foward.

Is there a function that I can get the sprite that I created before in a layer using layer_sprite_create() ?

I can't find it in the manual. Sorry for the dumb question.


Thanks!
 

chamaeleon

Member
Hi!


Pretty straight foward.

Is there a function that I can get the sprite that I created before in a layer using layer_sprite_create() ?

I can't find it in the manual. Sorry for the dumb question.


Thanks!
Assuming you have stored the return value of layer_sprite_create(), call layer_sprite_get_index() to get the sprite resource id back. Otherwise use the various layer_get functions (like layer_get_all_elements(), and so on) and optionally check if it's a sprite element using layer_get_element_type(). In the end you'll use layer_sprite_get_index() in order to get the sprite resource no matter which route you go. The "General Layer Functions" and "Sprite Layers" categories in the help is where you'll find the required information.
 

Kezarus

Member
So, no easy way to get sprite at a x/y?

Welp... then I store the sprite resource id on a grid...

It's the "easier" way, but there should be a function like instance_position for sprites on an asset layer. It's kinda dumb that it doesn't exist on GML. = /
 

chamaeleon

Member
So, no easy way to get sprite at a x/y?

Welp... then I store the sprite resource id on a grid...

It's the "easier" way, but there should be a function like instance_position for sprites on an asset layer. It's kinda dumb that it doesn't exist on GML. = /
I think it's not entirely unreasonable. Using a sprite layer as a means to create an environment that instances or whatever interacts with sounds like trying to use the layer for a purpose for which it was not created. If you need that kind of interaction, it seems like instances or tiles would be more appropriate. Having said that, I'm sure someone could come up with a reasonable counter-example.
 

GMWolf

aka fel666
You'd be defeating the point of using light weight sprites. The reason they are fast is that they are simple.

Welp... then I store the sprite resource id on a grid...
There are other alternative:

You could loop through every sprite in a layer and use layer_sprite_get_x/y to check if they are in the right position.
 

Kezarus

Member
@chamaeleon, in short I need snow to cover some tiles. If I do this on tiles I will screw the borders. The asset layer seems to be the path, but it have those caveats.

@GMWolf, loop through seems a little slow for what I'm planning.

I could store the sprite Ids on a grid. It's very simple to store, but then I will have to check for existence, remove when destroyed and all that jazz. Not feeling happy about it, but it is what it is.

Thanks very much for your help and support. Sorry if I said something stupid/rude. I'm just mad with GML and you guys are amazing as always.
 

GMWolf

aka fel666
@GMWolf, loop through seems a little slow for what I'm planning.
Probably not as bad as you may image, assuming you aren't doing it every step.
You may like to build some kind of acceleration structure, like a coarse grid of lists or something..

Im having déjà vu...
 

Kezarus

Member
@GMWolf, yep! This is for that problems of map making. =]

I have that map that can get to 500x500 cells. Make an auxiliary grid of that size is not an issue.

I think that a grid of lists for this case is unnecessary, as I could only have one snow spot per cell.

I made almost all of the code already. Dude, you helped a lot. Thanks again! I owe you a beer! =D
 
Top