i have ran into a quick problem which i do not know how to do it by myself but i'm sure with your help i will understand more.
I've created a level editor for the game engine i am creating and i am trying to make the mouse position snap to a 32x32(grid) or 64x64(grid) so that the tiles are placed correctly and not overlapping each other.
So that its not like this : https://i.stack.imgur.com/uL60U.jpg but more like this : http://imgur.com/a/nck9N Sorry for the really bad explanation.
The mouse position code i am using is
public int getMouseX() {
return mouseX; // Get MouseX
}
public int getMouseY() {
return mouseY; // Get Mouse Y
}
public void mouseMoved(MouseEvent e) {
mouseX = (int)(e.getX() / gc.getScale() /*+ gc.getWindow().getFrame().get*/);
mouseY = (int)(e.getY() / gc.getScale()); //CODE TO GET MOUSE X AND Y
}
//Code Which Loads the texture/image where the mouse is
tMouseX = gc.getInput().getMouseX() -32;
tMouseY = gc.getInput().getMouseY() - 32;
putImage((int)tMouseX,(int)tMouseY,r);
//putImage Function
public void putImage(int x, int y)
{
objects.add(new Grass(x,y));
}
Trying to make the images snap to 32x32