Browse Source

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
master
Abheek Dhawan 4 years ago
parent
commit
efec241911
  1. 1
      Game Scenes/Game.tscn
  2. 17
      Scripts/Rocket.gd
  3. 5
      Scripts/Text Container.gd
  4. 2
      export_presets.cfg
  5. 9
      project.godot

1
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="."]

17
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

5
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):
func _input(event):
if event is InputEventScreenTouch:
if event.pressed == true:
get_tree().change_scene("res://Game Scenes/Game.tscn")

2
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=""

9
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)
]
}

Loading…
Cancel
Save