0 votes

I'm working on a project follow a tutorial.

I'm trying to use Timer to set the time when a preloaded scene comes up on stage. It's a scene consisting of 8 other instanced scenes (I've already preloaded it in the stage scenes). When the scene comes up, the game window freeze for a moment which is hard to notice. But if I instance a bunch of scenes like that, the freezing will be obvious.

Thanks in advance.

Stage scene's scripts:

extends Node2D

var f_as1 = preload("res://elements/formations/f_alpha_straight_toptobot_ch1.tscn")
var aship = preload("res://elements/elements/e_enemy_alpha.tscn")

func _ready():

func _process(delta):
    yield($Timer, "timeout")
    var a = f_as1.instance()
in Engine by (65 points)

IDK if i understood corectly, but what you are trying to achieve is to instance the preloaded scene everytime $Timer timeouts?

1 Answer

0 votes
Best answer

If what you are trying to achieve is to instance the preloaded sceen always timer timeouts, then you should not use yield inside process function. Yield will make process function stop process execution untill timeout happens, and thats the lag. You should connect the timer's timeout signal to a _on_Timer_timeout() and instance the sceene there. Like:

func _on_Timer_timeout():
    var a = f_as1.instance()

Similar to what the "Your First Game" tutorial does for spawning mobs.

by (3,505 points)
selected by

I'm just new to this engine and programming. Thanks for your help!

You are welcome!

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.