Simple game running slow on android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WeTech

So I started with godot recently and went straight into making my first game. The problem is a simple code runs really slow and I have no idea how to change it. (found no working solution) . All the scenes are almost the same so far.
Tested device: Redmi note 4 and note 7
Scene: Node 2D - CanvasLayer (-TextureRect with image) and RichLabelText
The code:

extends Node2D
var swipe_start = null
var minimum_drag = 50
func _unhandled_input(event):
   if event is InputEventScreenTouch:
     if event.pressed:        
        
extends Node2D
var swipe_start = null
var minimum_drag = 50
func _unhandled_input(event):
  if event is InputEventScreenTouch:
    if event.pressed:
      swipe_start = event.get_position()
    else:
      _calculate_swipe(event.get_position())
func _calculate_swipe(swipe_end):
	if swipe_start == null: 
    return
	var swipe = swipe_end - swipe_start
	if abs(swipe.x) > minimum_drag:
		if swipe.x < -50:
			get_tree().change_scene("res://Beg1.tscn")

The delay between the swipe and change of scene is often 1-3s which feels terrific.
Played with fps a bit too and it shows about 20 drop from 60 when swiped.

:bust_in_silhouette: Reply From: Jason Swearingen

you need to preload the screen you are changing to.

currently you are only starting to load the scene when the user swipes. that means it has to load the screen from disk when that happens. instead, you should start loading the next screen once the current screen finishes loading.

hope that helps.

Awesome, thanks! I didnt know this existed. Now the intial loading takes a bit longer but it runs smooth and thats what I wanted.

WeTech | 2020-02-04 17:46