0 votes

What I'm trying to do is change the texture of the TextureRect node by uploading a new 600x600 jpg image from a folder in the device that contains a lot of images of the same size (about ten thousand images) when the button is clicked, using the database (sqlite) and the image_index variable, while there is a VideoPlayer node It works as an animated background.
The problem is when I press the button, it freezes for two or three seconds before loading the next image.

I would be grateful if examples are provided to fix the problem, since I'm actually new to godot


extends Sprite

const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
onready var my_database = SQLite.new()
var image_index = 0

func _ready():
    my_database.path = "res://images_data/images.db"
    my_database.open_db()
    my_database.query("SELECT id FROM datas ;")

func _on_Button_pressed():
    var test_image = Image.new()
    var test_texture_image = ImageTexture.new()
    image_index +=1
    test_image.load("/home/admin/Downloads/images/"+str(my_database.query_result[image_index]["id"])+".jpg")
    test_texture_image.create_from_image(test_image)
    get_node("../TextureRect").texture = test_texture_image
Godot version Godot_v3.4.4-stable_x11.64
in Engine by (14 points)

Do you know which part of the above code is slow? For instance, is it:

  • The sqlite query?
  • The image.load() call?
  • The create_from_image() call?

I'd probably split that sqlite query out as an independent line of code (so it can be easily analyzed separately) and then see where the delay is actually coming from. Once you know that, it'll give a better idea of how to improve it.

Sorry for the late reply, and thank you very much.
I took your advice, and after several attempts I came to a solution that is not perfect but acceptable.

It works fine, but the video in the video player node is getting a decrement in frame rate every time I click the load image button.

I'm going to ask a new question about that because it might be a different topic.

thank you very much.


extends Sprite

const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
onready var my_database = SQLite.new()
var image_index = 0


 func _ready():
     my_database.path = "res://images_data/images.db"
     my_database.open_db()
     my_database.query("SELECT id FROM datas ;")
     var database_result = my_database.query_result
     my_database.close_db()

func _on_Button_pressed():
     var test_image = Image.new()
     var test_texture_image = ImageTexture.new()
     image_index +=1
     test_image.load("/home/admin/Downloads/images/"+str(database_result[image_index]["id"])+".jpg")
     test_texture_image.create_from_image(test_image)
      get_node("../TextureRect").texture = test_texture_image

Please log in or register to answer this question.

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.