java - Filling a square with tiles -
i have 2d tile game trying create brush sizes for. currently, code looks this:
if (ismouseclicked0) { int grid_x = math.round(mousex / blocksize); int grid_y = math.round(mousey / blocksize); (int x = 0; x < brushsize; x++) { (int y = 0; y < brushsize; y++) { world.setat(grid_x, grid_y, b[inventoryselect]); grid_x += x; grid_y += y; } } }
the setat()
method looks this:
public void setat(int x, int y, blocktype b) { if (x <= display.getwidth() / blocksize && y <= display.getheight() / blocksize) { blocks[x][y] = new baseblock(b, x * blocksize, y * blocksize); } render(); }
this produces output:
the tile above first tile on top left clicked mouse, can see next tile isn't rendering. i've been @ hours, i'm missing simple. help?
edit: brush size 2
, should creating 4 tiles. blocksize
32
, it's how big blocks are.
the problem :
grid_x += x; grid_y += y;
you moving diagonally. might work better :
(int x = 0; x < brushsize; x++) { (int y = 0; y < brushsize; y++) { world.setat(grid_x + x, grid_y + y, b[inventoryselect]); } }
Comments
Post a Comment