Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hashak | |
Old Version | Published before Godot 3 was released. |
First sorry for poor English.
I am beginner in Godot and game development. I make a brick breaker 2d game with 7 level for android. Everything is OK But my problem is memory usage.
When i run my game (for test in Windows 7, Godot 2.1.4) and open Windows Task Manager (Performance tab), level after level increases memory and game will be lagging.
What can i do?
That sounds like a very small game, so my guess is you’re doing something very wrong. However, nobody can really give you advice unless you provide more information about how your game is set up. What is your scene/node setup? Your code? Have you tried narrowing down the problem?
kidscancode | 2018-01-14 04:46
My scene setup image direct link
Thanks for you answer. Can you tell what causes it to increase memory (For example a checklist)
It is my scene setup and i repeat these in other level. Level by level some object (like bricks) and animation are increase.
“audio” have several sound (StreamPlayer type).
“camera” have a code for shaking when ball is lose. (I learn this code from Angega Studios youtube user)
“Player” and “enemy” have 2 animation and i set those to play random when finished animation.
func _ready():
anim.connect("finished", self, "_random_animation")
func _random_animation():
var randNum = randi() % 2
if randNum == 0: anim.play("idle")
else: anim.play("ready")
“brick container” have 24 bricks, and level by level these will be increase.
“ball” have a for loop condition for collision check and bricks queue_free, play sound when contact to object. and a condition for check ball that when ball get out at scene, reset ball position for new game.
func _fixed_process(delta):
if _global.is_ball_play && self.get_global_pos().x <= 0:
self.set_sleeping(true)
self.set_pos(Vector2(220, 190))
_global.is_ball_play = false
container.add_child(fade_white.instance())
_global.player_life -= 1
camera.shake(8, 0.2)
ballSpeed = BALL_SPEED
if _global.is_sfx:
snd_ball_gone.play()
# Colliding ball
var collision = get_colliding_bodies()
for i in collision:
ballSpeed += 3
ballSpeed = clamp(ballSpeed, BALL_SPEED, BALL_SPEED*2)
# Ball sound
if _global.is_sfx:
snd_ball.play()
if i.is_in_group("g_brick"):
i.queue_free()
# Change direction ball by hit
if i.get_name() == "hit_player":
var p = i.get_node("position2D").get_global_pos()
var changPos = self.get_global_pos() - p
var velocity = changPos.normalized() * ballSpeed
self.set_linear_velocity(Vector2(velocity.x, velocity.y))
“container” is a place for add “white fade-out animation” when ball is lose and “hit shape” for change direction ball (like a paddle), and after finished animation these will be queue_free.
“ui” is a simple menu for go to next level, close or restart game.
I hope these information be enough
hashak | 2018-01-14 10:59
How are you loading new levels? I notice that you’ve named that scene “level_1” so I assume you have a scene for each level. Is it possible that you are not removing the scene for the previous level when the player continues?
literalcitrus | 2018-01-14 22:32
Thanks for your answer.
I add a global variable called “level_number” in AutoLoad. If player win in this level, a window will be open and there is “Next level button” inside that, If user click on that i add 1 to “level_number”. And change scene to next level with this:
func _on_pressed_next_level():
_global.level_number += 1
_global.is_ball_play = false
if _global.level_number < 8:
get_tree().change_scene("res://stages/level_%s.tscn" % str(_global.level_number))
else:
get_tree().change_scene("res://stages/level_end.tscn")
pass
hashak | 2018-01-15 03:44