First of all sorry, for my terrible writing im not good with it, but there is no need to hold back with your answers i only have problems when it comes to writing.
I started to write my own 2D Game Engine in Java for practice(and for fun) reasons. Until now i've made very good progress but i got a problem, which i got stuck on.
I started to build a basic tile picker (left click: setTile | right click: getTile). So far so fine, but here is the problem. The further away my mouse gets from the upper left corner of the screen, the more inaccurate the tilepicker gets.
In the picture, you can see the overall tile i clicked on (black cross) and the accurat point (orange dot). This would get me the blue tile underneath.
This is the code i used to translate the mouse coordinates to tile coordinates.
if(input.mouseleft.isClicked()) {
tx = (int) (Math.floor(world.getCamera().getX() + input.getMouseX()) / world.getTileSize());
ty = (int) (Math.floor(world.getCamera().getY() + input.getMouseY()) / world.getTileSize());
// Checks if the coordinates are within the tilemap
if(tx >= 0 && tx <= world.getWidth() && ty >= 0 && ty <= world.getHeight() )
world.setTile(holdtileid, tx, ty);
}
I hope somone can help me and thanks in advance.
↧