getMapLocations() and getMapAreas()
-
(Sniffing around other projects, at least Waldron also knows about this :) )
I just stumbled across these functions by accident via the code highlighter, they don't seem to be documented and I could not find them mentioned around here. What they do is they take a location resp. area name and give you an array of ALL the locations or areas with that name. Like getMapLocation() and getMapArea(), only for when you use the same name multiple times.
Please add them to the help, they are immensely useful and make putting data in maps easier! Say, if you want to spawn bats at selected locations, what you can do with these is just place down many markers called "BAT", then iterate over the return of getMapLocations("BAT") and put a bat there.Until then, I hope bringing them to people's attention this way... brings them to people's attention.
-
You are absolutely correct, and they will indeed be in the help in the next patch.
-
Could you possibly give an example of how these work I would love to use them!
-
@poof92 Sure, I'll turn the bats example into simple code:
var batImage = loadImage("Bat") // needs to exist, obv loadMap("Dungeon") // map with locations named "BAT" // get array of bat locations var batLocations = getMapLocations("BAT") // spawn them all var bats = [] for i = 0 to len(batLocations) loop var bat = createSprite() setSpriteImage(bat, batImage) setSpriteLocation(bat, batLocations[i]) bats[len(bats)] = bat repeat
Written mostly without explicitly testing it, errors you find are for you to correct :)
The shape data returned from getMapAeas() is harder to use and harder to find a use for; the collision checks with MapArea in their name already cover most use cases. I can think of three scenarios where you want the data:
- You want to roll your own collision detection
- You want to unload the map, but still use its data; then you'll obviously need to fetch and store it
- You want to automatically create 'popup' sprites for isometric/half top-down games. Say you have a tree on your map; if you just use normal rendering, your sprites will always appear on top of the tree and can't be behind the tree, but above the ground (you can do this with layers and lots of manual draw calls, but that is hard to get right). The easiest way to fix that is to turn the tree into a sprite and use the y coordinate of all sprites as their depth, then they get sorted automatically into the correct drawing order. For that, you need information which parts of the map to turn into sprites at what depth; those can be areas. The area "POPUP_LAYER_2" could tell the system to take the image inside the area on map layer 2 to create the sprite.
I should probably turn number 3 into a small demo project.
-
Awesome thanks a ton this will help alot
-
getMapAreas() demo project is done, share code UPS33MND51
In it, you define areas on the map where layers are to be turned into popups:
https://x.com/manuel_moos/status/1726301930375516509?s=20
And then these bits can be "walked around" in the game:
https://x.com/manuel_moos/status/1726302625375859071?s=20
(I'm working on getting the tags right, only a question of a couple of years!)It is not the most memory efficient way to go about planting a lot of identical trees, mind. If you have a managable set of possible things to populate your popup sprites with, use the BATS code, generalized. Easier, too.