0 votes

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.

in Engine by (18 points)

1 Answer

+1 vote
Best answer

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.

by (220 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.