Discuss Scratch

cs765885
Scratcher
1 post

detecting a section of a sprite

I'm working on a project where I have a large map, and I want to recognize and locate where certain patterns or sections within that map are.

Could I make a smaller sprite (like a cut out section) that resembles the part on the map that I want to locate, and then have it somehow detect its position within the map, essentially finding its location on the map? Maybe by moving the sprite around until it detects that the part of the map it is touching matches with itself perfectly? Or could I scan for a certain array of pixel colors that match the section I want to locate? How could I get this to work?
Wolf_Link21
Scratcher
100+ posts

detecting a section of a sprite

when you make the sprite, it could remember the x and y coordinates it has on the map, but I'm not totally sure if this is what you wanted.

This is dave
:D :: hat :: motion
He protects my from evil kumquats.
Please follow me if you find my response helpful and give me any ideas for my game https://scratch.mit.edu/projects/992371983/
27xz
Scratcher
57 posts

detecting a section of a sprite

Perhaps you could make the map in tiles, and the tile which you wish to detect could have a different ID using a “for this sprite only” variable? I would also use custom x and y variables to detect position.

Potatoes are good. Game dev is good. Potatoes in game dev is remarkable.
MrKingofScratch
Scratcher
100+ posts

detecting a section of a sprite

Yeah, you're idea was on the right track. Make another sprite that has just the area you want to “detect” (and lines up with the map). Then, can use the
set [ghost v] effect to (100)
block to make it invisible, but you can still detect it with
<touching [sprite v] ?>
If the map moves at all (like if it's scrolling) you can use
forever
go to [Map v]
end
This does lag behind one frame, but it shouldn't matter if you're only using it for a map.

I hope this helps, and if you can't understand this (I'm terrible at explaining things, sorry) let me know.
If this isn't what you were looking for, it would be helpful if you could let me know the bigger system that this area detection is a part of (ex detecting if a player enters an area or teleporting a player if they click on something)

Last edited by MrKingofScratch (March 25, 2024 21:40:06)


Last edited by kaj (Tomorrow 00:00:00)
100th post!

Powered by DjangoBB