Using Godot 4.2.1
when exporting my game to HTML5 it runs completely fine until an explosion effect is spawned on screen for the first time when killing a mob, the game freezes for an entire 2-3 seconds, an easy fix is to just spawn it at the startup of the game so that the freeze would happen at the start instead
func _ready():
var SMOKE_SCENE = preload("res://smoke_explosion/smoke_explosion.tscn").instantiate()
get_parent().add_child(SMOKE_SCENE)
SMOKE_SCENE.position = Vector2(0.0, 0.0)
print("spawned smoke")
but for some reason this isn't working and the smoke isn't being spawned at the start
func _ready():
var SMOKE_SCENE = preload("res://smoke_explosion/smoke_explosion.tscn")
var smoke = SMOKE_SCENE.instantiate()
get_parent().add_child(smoke)
smoke.position = Vector2(0.0, 0.0)
print("spawned smoke")
this also didn't work, the smoke isn't being spawned at the start
get_tree().add_child(smoke)
tried getting the tree instead of the parent but it doesn't help
I tried putting breakpoints in the _ready function to see if the smoke is actually being instantiated at the start and I noticed that it seems to be instantiated and put in the game before any of game graphics actually appear on screen, so it looks like it's appearing and disappearing before we even see it, so it fixes nothing
EDIT 1: here is the code of the explosion scene
extends Node2D
func _ready():
%Smoke.material.set_shader_parameter("texture_offset", Vector2(randfn(0.0, 1.0), randfn(0.0, 1.0)))
%AnimationPlayer.play("explosion")
await %AnimationPlayer.animation_finished
queue_free()
Node2D
with aControl
child, which I assume you are animating, and also setting shader parameters every time an explosion is instantiated. This looks expensive, given the platform you're targeting (Web), however, this can only be confirmed by the debugger: open the Debug > Monitor tab when running the game from the editor, and look for any odd spikes when an explosion appears on the screen. \$\endgroup\$CPUParticle2D
Node for your explosion: it exposes many parameters for randomising position and animation of particles in your games. \$\endgroup\$