HI, I finished making a game, it had no problem (decent framerate, objects behaved as expected, etc) but it turned out i was wrong....
On my crappy 1GB Ram tablet, the game crashes after playing for approximately 5 minutes, at first i thought it was just the custom rom I installed because it seems to not handle android apps too well. But when i ran the game on my PC and checked the task manager, the game kept increasing in memory usage again...and again..... especially when i was in the game scene which is arranged like this:
-game
-- player
-- enemyspawner
--- enemyonetimer
--- enemytwotimer
--- enemythreetimer
--- enemyfourtimer
-- invertedenemyspawner
--- (same child as enemyspawner only inverted now)
-- powerup_spawner
--- (some child scenes)
-- (more child scenes but don't have effect)
When i removed the spawner nodes, the memory usage issue was gone and when i changed scene to the main menu, some memory even got freed.
But when I had the spawners (especially the enemy ones) the memory usage just kept increasing and even when i changed scene to the main menu, the memory doesn't get freed
The enemy_spawner instanciates the enemy scenes and when the timer for the specific enemy runs out, it gets spawned and moves continueously to the right (inverted is to the left) I took a look at my enemy scenes (all are area2d, some have kinematicbody2d) and had them get queue_free()
when it reaches certain cordinates but that did not make a difference, the memory usage still increases
I read this issue with the scene memory, indicating that i should free the previously used scene but i don't know how to implement that on my stage manager script (from angegastudio flappy bird)
extends CanvasLayer
const GAME = "res://src/main/game.tscn"
const MENU = "res://src/main/menu.tscn"
var is_changing = false
signal stage_changed
func _ready():
pass
func change_stage(stage_path):
if is_changing: return
is_changing = true
get_tree().get_root().set_disable_input(true)
# fade to black
get_node("anim").play("fade_in")
audio_player.play("sfx_swooshing")
yield(get_node("anim"), "finished")
# change stage
get_tree().change_scene(stage_path)
emit_signal("stage_changed")
# fade from black
get_node("anim").play("fade_out")
yield(get_node("anim"), "finished")
is_changing = false
get_tree().get_root().set_disable_input(false)
pass