Hi,
I have been making maps for the various locations in my game, and I’ve been trying to place a marker on the player’s current position. I store that position as two variables for x and y, and the maps are grid-based (made using Inkarnate). I am struggling to get the images overlapping properly and any attempts to change the x, y coordinates of the marker have been fruitless (it only needs to change upon refreshing the passage).
Has anyone tried to do a similar thing? I don’t really have any example code, but I believe what had the closest results to what I want was this post.
You haven’t included an example of the code (HTML?, CSS?) you are currently using to display the “map”, which makes it difficult to give a detailed explanation on how to alter it to display a “marker” above a specific location on that “map”.
But as shown in the example you linked to, you can use CSS to position one HTML element above another as long as the structural relationship between those two elements is known.
Method 1: (as shown in the linked example)
If both the “map” element(s) and the “marker” element have a common parent element then setting that parent’s position property to relative allows a child element to be positioned within the bounding box of that parent element.
This is done by setting the position property of the child element to absolute and then using the top / left / bottom / right properties of that child to control its location within the parent’s bounding box.
note: you may also need to assign the child element a higher z-index property value than that of the parent element.
Method 2:
If the “map” image is being displayed as the background image of an element, then you can use a technique similar to method 1 to position a “marker” element that is made a child of that “map” element.
…and the CSS for positioning that “marker” image would use the same technique as the linked example, with a slight change to display the background image…
#map {
background-image: url('http://i.stack.imgur.com/Blaly.png');
/* may need more background related property settings to control the displaying of the image */
}
#marker {
position: absolute;
bottom: 0;
right: 0;
}
warning: None of the above code examples have been tested, as I didn’t know how you have implemented things in your project.