Sfoglia il codice sorgente

Fix for negative coords. Regarding issue #2665

int() of negative numbers rounds up. Needed to add a condition to account for negative values. Thanks to Romulox_x for providing this solution.
Brickcaster 10 anni fa
parent
commit
4e0511a8a0
1 ha cambiato i file con 2 aggiunte e 3 eliminazioni
  1. 2 3
      scene/2d/tile_map.cpp

+ 2 - 3
scene/2d/tile_map.cpp

@@ -1031,13 +1031,12 @@ Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
 	switch(half_offset) {
 
 		case HALF_OFFSET_X: {
-			if (int(ret.y)&1) {
-
+			if ( ret.y > 0 ? int(ret.y)&1 : (int(ret.y)-1)&1 ) {
 				ret.x-=0.5;
 			}
 		} break;
 		case HALF_OFFSET_Y: {
-			if (int(ret.x)&1) {
+			if ( ret.x > 0 ? int(ret.x)&1 : (int(ret.x)-1)&1) {
 				ret.y-=0.5;
 			}
 		} break;