Method: MiniGL::Map#get_map_pos
- Defined in:
- lib/minigl/map.rb
#get_map_pos(scr_x, scr_y) ⇒ Object
Returns the tile in the map that corresponds to the given position in the screen, as a Vector, where x is the horizontal index and y the vertical index.
Parameters:
- scr_x
-
The x-coordinate in the screen.
- scr_y
-
The y-coordinate in the screen.
92 93 94 95 96 97 98 99 100 |
# File 'lib/minigl/map.rb', line 92 def get_map_pos(scr_x, scr_y) return Vector.new((scr_x + @cam.x) / @tile_size.x, (scr_y + @cam.y) / @tile_size.y) unless @isometric # Gets the position transformed to isometric coordinates v = get_isometric_position scr_x, scr_y # divides by the square size to find the position in the matrix Vector.new((v.x * @inverse_square_size).to_i, (v.y * @inverse_square_size).to_i) end |