From efec241911657f95cee09bc0066d488074ccdbff Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Mon, 16 Nov 2020 12:16:57 -0600 Subject: [PATCH] Change input method Instead of looking for mouse presses every frame, which caused a decent amount of lag, I changed the input method to look for touch input, which decreased lag and improved the experience --- Game Scenes/Game.tscn | 1 - Scripts/Rocket.gd | 17 ++++++++++++++--- Scripts/Text Container.gd | 7 +++++-- export_presets.cfg | 2 +- project.godot | 9 ++------- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Game Scenes/Game.tscn b/Game Scenes/Game.tscn index 29f6a3b..af7e22c 100644 --- a/Game Scenes/Game.tscn +++ b/Game Scenes/Game.tscn @@ -79,7 +79,6 @@ __meta__ = { position = Vector2( -8.0022, -34.2137 ) scale = Vector2( 0.401688, 0.401688 ) frames = SubResource( 6 ) -frame = 1 playing = true [node name="ParallaxBackground" type="ParallaxBackground" parent="."] diff --git a/Scripts/Rocket.gd b/Scripts/Rocket.gd index 682a188..110bbd2 100644 --- a/Scripts/Rocket.gd +++ b/Scripts/Rocket.gd @@ -5,6 +5,8 @@ var difficulty var deltaDifficulty = 0 var explosionObj = load("res://Objects/Explosion.tscn") var collided = false +var isScreenPressed = false +var screenPressLocation = get_viewport().get_rect().size/2 onready var gameNode = get_node("/root/Game") func _process(delta): @@ -26,15 +28,24 @@ func _process(delta): yield(get_tree().create_timer(1.5), "timeout") queue_free() get_tree().change_scene("res://Game Scenes/MainMenu.tscn") - if Input.is_mouse_button_pressed(BUTTON_LEFT): - if (get_viewport().get_mouse_position().x <= get_viewport_rect().size.x/2): + if isScreenPressed: + print (true); + if (screenPressLocation <= get_viewport_rect().size.x/2): if angle > -1.5: rotate(-0.05) angle -= 0.05 - elif (get_viewport().get_mouse_position().x > get_viewport_rect().size.x/2): + elif (screenPressLocation > get_viewport_rect().size.x/2): if angle < 1.5: rotate(0.05) angle += 0.05 else: rotate(-angle/25) angle -= angle/25 + +func _input(event): + if event is InputEventScreenTouch: + if event.pressed == true: + isScreenPressed = true + screenPressLocation = event.position.x + if event.pressed == false: + isScreenPressed = false diff --git a/Scripts/Text Container.gd b/Scripts/Text Container.gd index 6410ae5..f04cef8 100644 --- a/Scripts/Text Container.gd +++ b/Scripts/Text Container.gd @@ -5,5 +5,8 @@ var time = 0 func _process(delta): time += delta rotation = sin(time)/10 - if Input.is_mouse_button_pressed(BUTTON_LEFT): - get_tree().change_scene("res://Game Scenes/Game.tscn") + +func _input(event): + if event is InputEventScreenTouch: + if event.pressed == true: + get_tree().change_scene("res://Game Scenes/Game.tscn") diff --git a/export_presets.cfg b/export_presets.cfg index 2a1a072..6b1263b 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -137,7 +137,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="Builds/spacescape2d.ipa" +export_path="../ios/spacescape.ipa" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key="" diff --git a/project.godot b/project.godot index 302157a..fcc0de3 100644 --- a/project.godot +++ b/project.godot @@ -28,14 +28,9 @@ window/size/height=1792 [input] -turn_left={ +turn={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) - ] -} -turn_right={ -"deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) ] }