Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hidemat |
So I’m trying to make a tetris-like game. I’ve come pretty far but I’ve run into a problem I’m not quite sure how to fix. I have a Piece
(KinematicBody2D
) scene that runs on a _physics_process
loop for falling and movement from left to right. Which works ok.
But I want the parent Grid
(Node
) to have a STATE {IDLE, PIECES_FALLING, PIECES_BREAKING}
variable, and tell the Piece only to fall if the PIECES_FALLING
state is active. The approach I took in the parent grid was something like this:
func _process(delta):
match state:
STATE.IDLE:
if Input.is_action_just_pressed("start"):
state = STATE.PIECES_FALLING
STATE.PIECES_FALLING:
#check for pieces that need breaking
if pieces_need_breaking():
state = STATE.BREAKING
STATE.PIECES_BREAKING:
# break pieces
state = STATE.PIECES_FALLING
And it works, but it gets really laggy after the first cycle. So I was wondering how to fix this approach? Is it at all good, or should I just discard it and try something else?
The lag could be due to checking the state during each cycle of _process()
, which I think is each frame. Maybe there’s some other way to check it without using _process()
so much?
Ertain | 2019-11-04 19:22