I'm trying to make a minimap for a game I'm working on and I want it to display at the bottom-right corner of my canvas even when I change the size of the window.
I have a jquery code to change the size of canvas and my global WIDTH and HEIGHT variables when it changes:
$(window).resize(function()
{
ctx.canvas.width = $(window).width();
ctx.canvas.height = $(window).height();
WIDTH = $(window).width();
HEIGHT = $(window).height();
});
Here's what I have right now but it's not really working great:
var minimap = // Object to draw minimap (in-progress)
{
width: WIDTH / 5,
height: HEIGHT / 5,
x: ((WIDTH / 5) * 4),
y: ((HEIGHT / 5) * 4)
};
var updateMiniMap = function()
{
var HorW = (HEIGHT < WIDTH) ? HEIGHT : WIDTH;
minimap.width = HorW / 5;
minimap.height = HorW / 5;
minimap.x = ((WIDTH / 5) * 4);
minimap.y = ((HEIGHT / 5) * 4);
};
Here's what I want:
_______________ | | | | | | | ----| |__________|___|
and when the window gets smaller the square stays the same size:
____________ | | | ----| |______|___|