Calculate Tile Size?

So I'm trying to make a map that loops horizontally, but not vertically; this was easy enough. My code goes through and reads each cell of a ds grid and draws a different colour pixel on the screen depending on what value it holds. I have a "zoom" variable that is somewhere between 1 and 0, then multiplies the width, height, x and y of the camera so that the program doesn't go through every single tile on the map every step. when the zoom is smaller than 1, in the draw event, I have an if statement that draws a rectangle instead of a pixel. My problem is, when I'm zoomed in, the rectangles are either too big or too small. I've tried a couple different ways of incorporating zoom and the actual pixel width I need, but I feel like the solution here would be to calculate the tile width for each level of zoom. I'm not sure how to do this though, and I was wondering if anyone would be able to help. I'm using 1.4.

cx and cy are camera x and camera y, the starting tile for the draw

xx and yy are the for loop counters for the respective axis

vw and vh are width and height for the camera

bloc is my feeble attempt at calculating my tile size

Relevant draw event code:
GML:
else if zoom != 1
{
    draw_rectangle((((xx-cx))/zoom)-bloc,((yy-cy)/zoom)-bloc,((xx-cx)/zoom)+bloc,((yy-cy)/zoom)+bloc,false)
}
scr_zoomvar (called every time the zoom is changed, in increments of 0.1):
GML:
cx = 0*zoom;
cy = 0*zoom;
vw = 400*zoom;
vh = 400*zoom;
bloc = 5*(1.1-zoom);
tl;dr, I'm trying to draw squares that dont overlap and dont have gaps for different levels of zoom without using the built in view system that I might replace with sprites if the zoom is great enough but I need to know if I should change my way of working with this. Thanks in advance.
 

rytan451

Member
As an alternative, have you considered drawing the map to a surface (with each tile being 1 pixel) and drawing that surface scaled up and without antialiasing?

And width would be base tile width (width before zooming) times zoom
 

Yal

šŸ§ *penguin noises*
GMC Elder
If you know the zoom factor (aka, how many percent it magnifies / diminishes sizes) you could just multiply your base tile size (16, 32 or whatever) with that. And the zoom factor is basically size of the viewport / region sampled in room, e.g. if you have a 320x180 viewport and the view in the room is 640x360, that means you have a zoom factor of 0.5, so you should draw the tiles at half size in the view (since you don't actually resize the view, you just change the sample area)
 
Top