I've got into game development, and I decided to choose Godot as the game engine because C# was supported, and I knew the language. I've been working on a simple game, and at some point, I ran into a problem. I wanted to make a sprite invisible when a key was pressed. I wanted It so if the key was pressed, it did an action permanently.
I tried this, but Input.IsPhysicalKeyPressed((int)) stopped the action as soon as I released the key
public override void _PhysicsProcess(float delta)
{
Visible = true;
if (Input.IsPhysicalKeyPressed((int)KeyList.W) || Input.IsPhysicalKeyPressed((int)KeyList.A) || Input.IsPhysicalKeyPressed((int)KeyList.S) || Input.IsPhysicalKeyPressed((int)KeyList.D))
{
Visible = false;
}
else if (Input.IsPhysicalKeyPressed((int)KeyList.Up) || Input.IsPhysicalKeyPressed((int)KeyList.Left) || Input.IsPhysicalKeyPressed((int)KeyList.Down) || Input.IsPhysicalKeyPressed((int)KeyList.Right))
{
Visible = false;
}
}
How do I fix this problem?
Visible = true;
the problem? If your game runs at 60fps, I imagine that_PhysicsProcess
is being executed 60 times a second. Wouldn't that immediately make the item visible again when you release whichever key of WSAD⬆️⬇️⬅️➡️ you have pressed?Visible = true;
and that will solve it, won't it?