getting close with android inutr
This commit is contained in:
parent
fec645d6b3
commit
706590e3dd
43
Camera2D.gd
43
Camera2D.gd
@ -2,12 +2,20 @@ extends Camera2D
|
|||||||
|
|
||||||
var last_mouse_position = Vector2.ZERO
|
var last_mouse_position = Vector2.ZERO
|
||||||
|
|
||||||
|
var touch_start_positions = {}
|
||||||
|
var last_zoom_distance = -1
|
||||||
|
var last_zoom_center = Vector2.ZERO
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_process_input(true)
|
set_process_input(true)
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
print(event.as_text())
|
print(event.as_text())
|
||||||
|
|
||||||
|
handle_mouse_events(event)
|
||||||
|
handle_touch_events(event)
|
||||||
|
|
||||||
|
func handle_mouse_events(event):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
||||||
last_mouse_position = get_global_mouse_position()
|
last_mouse_position = get_global_mouse_position()
|
||||||
@ -36,3 +44,36 @@ func zoom_towards_mouse(zoom_factor):
|
|||||||
zoom *= zoom_factor
|
zoom *= zoom_factor
|
||||||
var diff = previous_mouse_position - get_local_mouse_position()
|
var diff = previous_mouse_position - get_local_mouse_position()
|
||||||
position += diff
|
position += diff
|
||||||
|
|
||||||
|
func handle_touch_events(event):
|
||||||
|
if event is InputEventScreenTouch:
|
||||||
|
if event.pressed:
|
||||||
|
touch_start_positions[event.index] = event.position
|
||||||
|
if len(touch_start_positions) == 2:
|
||||||
|
last_zoom_distance = touch_start_positions[0].distance_to(touch_start_positions[1])
|
||||||
|
last_zoom_center = (touch_start_positions[0] + touch_start_positions[1]) / 2.0
|
||||||
|
else:
|
||||||
|
touch_start_positions.erase(event.index)
|
||||||
|
last_zoom_distance = -1
|
||||||
|
last_zoom_center = Vector2.ZERO
|
||||||
|
|
||||||
|
elif event is InputEventScreenDrag:
|
||||||
|
if event.index in touch_start_positions:
|
||||||
|
touch_start_positions[event.index] = event.position
|
||||||
|
if len(touch_start_positions) == 2:
|
||||||
|
var new_zoom_center = (touch_start_positions[0] + touch_start_positions[1]) / 2.0
|
||||||
|
var new_zoom_distance = touch_start_positions[0].distance_to(touch_start_positions[1])
|
||||||
|
|
||||||
|
if last_zoom_distance > 0:
|
||||||
|
var zoom_factor = last_zoom_distance / new_zoom_distance
|
||||||
|
zoom_towards_point(last_zoom_center, zoom_factor)
|
||||||
|
position -= (new_zoom_center - last_zoom_center) / zoom
|
||||||
|
|
||||||
|
last_zoom_distance = new_zoom_distance
|
||||||
|
last_zoom_center = new_zoom_center
|
||||||
|
|
||||||
|
func zoom_towards_point(zoom_center: Vector2, zoom_factor: float):
|
||||||
|
var local_zoom_center = (zoom_center - global_position) / zoom
|
||||||
|
zoom *= Vector2(zoom_factor, zoom_factor)
|
||||||
|
var diff = local_zoom_center - (zoom_center - global_position) / zoom
|
||||||
|
position += diff
|
||||||
|
@ -8,7 +8,7 @@ custom_features=""
|
|||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter="saves/*"
|
include_filter="saves/*"
|
||||||
exclude_filter=""
|
exclude_filter=""
|
||||||
export_path="bin/alpha11.apk"
|
export_path="bin/alpha104.apk"
|
||||||
encryption_include_filters=""
|
encryption_include_filters=""
|
||||||
encryption_exclude_filters=""
|
encryption_exclude_filters=""
|
||||||
encrypt_pck=false
|
encrypt_pck=false
|
||||||
|
@ -72,5 +72,4 @@ escape={
|
|||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
renderer/rendering_method="gl_compatibility"
|
|
||||||
textures/vram_compression/import_etc2_astc=true
|
textures/vram_compression/import_etc2_astc=true
|
||||||
|
Loading…
Reference in New Issue
Block a user