Iavra Minimap

Description


Creates a minimap based on either supplied pictures or generated from terrain tags.


Author


Iavra


Parameters


@param Switch
@desc Optional switch, that needs to be set to ON for the map to be active.
@default

@param Notetag
@desc Notetag used to mark maps, events and actors that should show up on the minimap.
@default minimap

@param Frame
@desc X, Y, width and height of the minimap. Negative coordinates start at the right/bottom of the screen.
@default 10, 10, 200, 200

@param Tile Size
@desc Size of a single tile on generated maps. Odd numbers might lead to graphical glitches. Minimum: 2
@default 10

@param Terrain Colors
@desc Comma-separated list of <terrainTag>:<color> pairs. Colors are specified in hex format.
@default 0:#FFF

@param Background Color
@desc Color to be used for the minimap background, in hex format.
@default #FFF

@param Background Opacity
@desc Opacity to be used for the minimap background. 0 is fully transparent, 1 is solid.
@default 0.3




Video










How to Use


To enable the minimap for a specific map, put this tag inside the map's notebox (configurable):


<minimap>


The plugin will then automatically create a minimap from terrain tags, using the colors provided via the plugin parameter "Terrain Colors". If you want to use a custom map, instead, modify the tag like this:


<minimap img:myImage>


The given image will be loaded and automatically scaled to fit the tile size specified in "Tile Size", so please make sure it has the right dimensions or you might experience graphical glitches.



To display the player icon on the map, put the following tag inside the notebox of an actor:


<minimap 1>


This will cause the icon #1 to be displayed on the minimap, as long as that actor is the current leading player. Different icons can be specified for each actor, so the minimap always shows the correct one.


To display an event on the map, put the following tag inside a comment:


<minimap 2>


As long as that page is active, the icon #2 will be shown at that event's position. This can be used to create marker events displaying PoIs or the current quest target.

The following script calls can be used to modify the map. Please note, that parameter changes are all temporary, unless another plugin stores them in a persistent manner:


IAVRA.MINIMAP.refresh();
Refreshes the map image loaded or created for the current map.

IAVRA.MINIMAP.move(x, y);
Repositions the map. Negative values are counted from the right/bottom edge.

IAVRA.MINIMAP.resize(w, h);
Resizes the map. If needed, it's repositioned to fit against the screen edge.

IAVRA.MINIMAP.x = value;
Repositions the map. Negative values are counted from the right edge.

IAVRA.MINIMAP.y = value;
Repositions the map. Negative values are counted from the bottom edge.

IAVRA.MINIMAP.width = value;
Resizes the map, updating its position if needed.

IAVRA.MINIMAP.height = value;
Resized the map, updating its position if needed.

IAVRA.MINIMAP.center = value;
Treates the given character as the new center of the minimap.

IAVRA.MINIMAP.zoom = value;
Changes the zoom level (doesn't effect icons, only the map itself).

IAVRA.MINIMAP.opacity = value;
Changes the overall opacity of the map. A value of 0 or lower will disable it.




Terms of Use


Free to use for both commercial and non-commercial games. Please give credit.


Download


Core: http://pastebin.com/z4Wy7MX4


Menu: http://pastebin.com/d0kGBcUb


Latest Changes


1.00 - Optimized the way events are handled, so the plugin will only create sprites for events, that are actually displayed on the map.


1.01 - Updated the minimap for 1.3. The menu extension has been cut and will be added later as its own plugin.


1.04 - Multiple bug fixes regarding map pictures and icon indizes.
no screenshots? boooo!!

Side note. I was considering doing a minimap system. With the feature of 'map areas are not displayed until you have explored that area' (similar to final fantasy games, where you get a 'map complete' each time you fully explore an area, and then some bonus rewards for that).

Maybe you could do such a feature ? 🙂
Sounds definitely interesting. I'll have to think about how i want to solve this. Since the minimap is created once on map load (or whenever IAVRA.MINIMAP.refresh() is called), i'll either need to blt only visible parts of the minimap on each update or (way easier, no idea about performane) refresh the map every time the player moves to a previously unvisited tile.
Hook into that method that is called (forgot name) when the player finishes moving onto a tile. So it's not done every update. Or when he leaves a tile. And then reveal x tiles around the player.


Also only blt() the tiles in range of the player (the ones to be revealed) and those that have not been drawn already, do not refresh the entire minimap for this.


And ofcourse only blt the ones unvisited.


This way it will hardly impact performance and it shouldn't be hard to implement.
Yeah, this seems like the right way:


- On map load / refresh create a blank bitmap and blt all discovered tiles on it.


- On visiting a new tile, blt it on the bitmap.


- Store stuff in $gameSystem, to make it persistent.
Hook into that method that is called (forgot name) when the player finishes moving onto a tile. So it's not done every update. Or when he leaves a tile. And then reveal x tiles around the player.


Also only blt() the tiles in range of the player (the ones to be revealed) and those that have not been drawn already, do not refresh the entire minimap for this.


And ofcourse only blt the ones unvisited.


This way it will hardly impact performance and it shouldn't be hard to implement.
Players aren't the only things that move.


I would include events as well. And anything else that can move.
Why should other events remove the fog of war for the player? If you meant it differently, i won't show events on unknown places (unless they are marked always visible in their notetag). I'll probably add a public method to reveal position (x,y), though.
Oh I did a mini map script too. Seems to be a popular choice these days.

People like to see icons on the mini-map so you might want to consider that. (icon for shop, maybe one for church to get healed etc.)

They like to be able to adjust transparency and zoom.

In regards to making it so you only see what you have explored: do no update every frame like I did. It causes considerable lag. (although it did work)
I'm currently redrawing the map every frame, so it automatically adapts to changes. Also, the only alternative to clearing and blt'ing seems to crop all child of the sprite container, since the viewport concept of Ace doesn't work anymore <.<


Icons are already possible with the event notetag. Actually, i'm currently allowing for arbitrary pictures, but icons might be a better idea, since it makes it easier to predict everything and users don't need to place a bunch of additional files in the game folders (also reduces the number of async loading).


I'll add transparency/zoom settings together with fog of war, since i will need to store stuff in the savefiles, anyway.
Why should other events remove the fog of war for the player? If you meant it differently, i won't show events on unknown places (unless they are marked always visible in their notetag). I'll probably add a public method to reveal position (x,y), though.
One of your note-tags allows you to tag an event. If the event moves around, the marker on the mini-map should be updated to reflect their new position.


This was in response to the suggestion that you only need to update the mini-map if the player moves.
But that doesn't require to blt() the whole map again. JUST the events on top of it. Regarding FoW this changes nothing I think.
Turns out clearing and blt'ing the minimap contents onto the sprite every frame costs up to 10 fps in chrome :/

I'll change this to work with multiple sprites, that i only update whenever something changes and manually crop them to keep inside the minimap bounds (sigh...).

/edit: Should i be afraid, if my functions begin like this? xD

var d, e, x, y, icon, s = this._spriteEvents, events = _events, set = ImageManager.loadSystem('IconSet');//edit: Got it running with a stable 60 fps (not uploaded, yet, i'm doing fog of war first). Took me a while to realize, that i shouldn't move the map sprite, but only move the frame looking at the underlying bitmap.Basically, the minimap has 3 main functions now:

- initialize/createAllSprites: Creates 4 sprites (background, map, events, player) and initializes then. Background, map and events all have the same size.

- update: Redraws events (got no better solution, since i would need to observe all event movements) and updates the frame of map/events, to only show the part currently visible.

- refresh: Called once at startup and on demand. Retrieves the current player icon and map image and sets up the sprites with them.

///edit: Seems like changing the frame of a sprite incredibly messes up the snapToBitmap method. Seems like i stumbled over this one here:

https://github.com/pixijs/pixi.js/issues/1258

https://github.com/pixijs/pixi.js/issues/1493

As soon as i set a negative y value for the frame, it gets inverted during snapForBackground.

////edit: So, i wanted to use mask instead of frame, but this causes weird polygones to render once i open the menu...

This is how it looks 😳

error.png

/////edit (look at all those slashes): I'll use blt for now. It's probably still slower than moving the frame/setting a mask, but at least it works perfect and i can concentrate on more features for now.
I think I just used the setFrame function. I will say though the polygon menu thing looks cool.
My offset method is currently flexible enough to center the map on anything, not only $gamePlayer, so i might add the option to snap it to a given event (or even any coordinates), if people would like this.


/edit: If fog of war is enabled, you might need to reveal that location first or the map would be blank ^^


I'm also currently pondering how to store the revealed tiles for all maps. Using a 2-dimensional array is easy, but wasteful, so i'll probably use a binary format (similar to how map flags are handled). I'll still need a single array to handle rows/columns, though.
My offset method is currently flexible enough to center the map on anything, not only $gamePlayer, so i might add the option to snap it to a given event (or even any coordinates), if people would like this.

/edit: If fog of war is enabled, you might need to reveal that location first or the map would be blank ^^

I'm also currently pondering how to store the revealed tiles for all maps. Using a 2-dimensional array is easy, but wasteful, so i'll probably use a binary format (similar to how map flags are handled). I'll still need a single array to handle rows/columns, though.
I used a two dimensional array but I don't really know what would be the most effective way. 
I fixed my frame problem by using a modified version of your solution (note, that there is no scaling so far):

$.prototype._updateMap = function(offset) { var sprite = this._spriteMap, s = _params.tileSize var x = Math.round(offset.x - s / 2), y = Math.round(offset.y - s / 2); sprite.setFrame(-Math.min(0, x), -Math.min(0, y), this.width - Math.max(0, x), this.height - Math.max(0, y)); sprite.move(Math.max(0, x), Math.max(0, y));};The Math.round()s are to prevent stuttering.I offset my map by tileSize / 2, so everything drawn on the map is displayed in the center of a tile an not on its upper left corner.

"offset" is the current map (and event) position relative to any given x/y coordinates. This is usually $gamePlayer._realX, $gamePlayer._realY, but can also be used to center the map on anything else.
Getting the map to zoom in and out and stay within the frame while also updating the icons and scrolling was fun.

Lots of math and sketches. 
Progress / Current features:


- Display minimap at any position and in any size.


- Optionally toggle minimap display via switch.


- Color minimap background + transparency.


- Automatically create minimap from terrain tags or use a custom image (it's easy to add alternative ways, too).


- Display events on the map via notetag on active page.


- Optionally show an event icon at the border of the minimap, even if it's outside the visible part (to serve as direction marker).


- Display player icon depending on currently leading actor.


- Zoom in/out (currently only via script call and not persistent).


Planned features, so far:


- Transparency settings (easy).


- Store zoom and transparency in ConfigManager and make editiable via option menu (easy ~ medium).


- Fog of war, hide all tiles except for visited ones (+ radius around them?) (medium ~ hard, depending on flexibility).


(- Center minimap on x/y coordinates, let it follow an event) (probably on the harder side).


Requests, anybody?


/edit: Regarding fog of war: There probably won't be an option to see, if a whole map has been revealed, since you would likely need a FoW plugin for the "real" map, as well, which would handle this (i plan to do one at some point).
This plugin has now been officially released. Fog of war is currently not part of it, but if i write my fog of war plugin (for the "real" map), i'll make it compatible with this plugin, so both maps show the correct state.


Also: I did a video!
Hi!!!

I put <minimap 400> command in an Actor's notetag, But it doesnt display 400th Icon...

It displays another random Icon from first rows...

🙁   🙁   🙁

Original thread: https://forums.rpgmakerweb.com/threads/iavra-minimap.51326/