KOBUGE-Games / space-settlers

A colonization board-game in space
16 stars 6 forks source link

Screen scrolling #3

Open bojidar-bg opened 8 years ago

bojidar-bg commented 8 years ago

The camera should be moved when the cursor goes near the edge of the screen (RTS style).

Sample code:

var camera_move = Vector2(0,0)

#...Other ways to move the camera...

var mouse_move = (get_global_mouse_pos() - camera.get_global_pos()) / get_viewport_rect().size * get_viewport_transform().get_scale() * 2
var mouse_distance = max(abs(mouse_move.x), abs(mouse_move.y))

if mouse_distance > 0.9:
    camera_move += mouse_move

camera.set_pos(camera.get_pos() + camera_move * camera_speed * delta )