Hi everyone . Sorry to bother you again. I've finish making Dodge the Creeps game by following the tutorial, and there are some things that are bothering me.
First, is this segment of code from the tutorial:
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
I changed it to this and the game still works the same:
if Input.is_action_pressed("ui_right"):
velocity.x = 1
if Input.is_action_pressed("ui_left"):
velocity.x = -1
if Input.is_action_pressed("ui_down"):
velocity.y = 1
if Input.is_action_pressed("ui_up"):
velocity.y = -1
My question is, why did the coder use the first code instead of the second code?
Second thing, is the fact that the input is being checked in the func process():. I am reading this:
https://docs.godotengine.org/en/stable/getting_started/workflow/best_practices/godot_notifications.html
it says checking for input should be done elsewhere
"While it is possible, to achieve the best performance, one should avoid making input checks during these callbacks. process and physics_process will trigger at every opportunity (they do not "rest" by default). In contrast, input callbacks will trigger only on frames in which the engine has actually detected the input."
Is there any reason for the coder to not use _input callbacks for this?
Thanks.