Easiest way to get Sprite at position

atmobeat

Member
Greetings gamemakers! Is there a sprite equivalent of tilemap_get_at_pixel? If I place some sprites on an asset layer but later want to check a position for some sprite, how might I do that? And just fyi, the sprite may be on a completely different layer than the one I placed it on in the room editor so I'm not sure any of the sprite layer functions will help.

I hope it's possible because I've run into a bit of a wall with this.
 

atmobeat

Member
A quick Google revealed this - https://forum.yoyogames.com/index.php?threads/solved-find-a-certain-sprite-in-assets-layer.56895/

I know you mentioned the layer may change, but you can name the sprites in the room editor, so you may need to loop through layers in that case to find the one you need.
Thanks TheSly but it looks like to use layer_sprite_get_id you have to already know the asset name from the room editor. That's about as specific as the sprite element ID. I'd like to be able to get the sprite element ID using code but it doesn't seem like there's a way to get the asset name except in the room editor. That's pretty restrictive. Imagine if you could only get an instance ID from the room editor. There are lots of times you want to get an instance's ID using code to manipulate that particular instance (especially since you can't count on always knowing the instance ID from the room editro). GMS2 has ways to get instance IDs and tiles at a point. I just figured there would be something similar for sprites. It seems like sprite elements are not intended to be manipulated all that much in GMS2.

I was hoping to be able to use some sprites in place of objects for things that are basically just depth-sorted and can only really be interacted with by destroying them and maybe sprite collision checking.
 

Slyddar

Member
Well the things you are wanting to do are things only objects can do. Maybe the 'light' objects, that get released in a future patch, will help. They have limited functionality, less impact on performance, and may do what you need.
 

atmobeat

Member
Well the things you are wanting to do are things only objects can do. Maybe the 'light' objects, that get released in a future patch, will help. They have limited functionality, less impact on performance, and may do what you need.
You may be right that the new objects could be helpful for me.

For now, I do initially place all of the sprites on a single asset layer before sorting them and I get all the element IDs just before putting each sprite element on its correct layer, so perhaps I can just store the element IDs I'm wanting to manipulate in a data structure and somehow loop through those elements to find the right one when I need it.

I'll see what I can come up with...
 

atmobeat

Member
Well the things you are wanting to do are things only objects can do. Maybe the 'light' objects, that get released in a future patch, will help. They have limited functionality, less impact on performance, and may do what you need.
Sorry, just wanted to add that tiles also have the functionality I'm looking for and I don't see a reason in principle there couldn't be a similar way to get a sprite element at a position as a tile or instance. There could definitely be something about the inner workings that I don't know about that makes what I want impossible.
 
Top