i see the function mget() that will return the sprite index of the map coordinates, but i need to get the sprite index of a sprite that is drawn to the screen using spr(). how can this be achieved in the simplest way?
Thank you in advance!
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/10844/dino.png)
Hi Mrbstro,
I think what you are looking for may be table of sprites.
After you have the sprites in a table, you can simply search through each sprite in the table to find one that matches both the x and the y value that you specify.
See un-validated code snippet below:
sprite_list = {}
function add_sprite(index,x,y)
a={}
a.index=index
a.x=x
a.y=y
add(sprite_list,a)
end
function draw_sprites()
for the_sprite in all(sprite_list) do
spr(the_sprite.index,the_sprite.x,the_sprite.y)
end
end
function find_sprite(x,y)
for the_sprite in all(sprite_list) do
if(the_sprite.x==x and the_sprite.y==y)then return the_sprite.index end
end
return false -- we didn't find anything
end
One note is that the x and y of the sprite have to be exactly the same as the x and y you are searching for.
Does that help?
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi3.png)
Oh wow thank you for the reply. Your method really made me think outside the box for this one i figured it out.
Thank you!
[Please log in to post a comment]