Ok, I see several things :) You are using Godot 2.1 right?
Firstly, with this configuration, adding more sprites and more collision shapes will make the code harder and harder to maintain. If you need to display for your player only one sprite and one corresponding collision shape, you definitely need to organize your code as a Finite State Machine. Here is an example that will make your code more readable, and less exposed to bugs:
func _fixed_process(delta):
velocity = Vector2()
if Input.is_key_pressed(KEY_PERIOD):
_switch_state(shape12, sprite11)
elif Input.is_key_pressed(KEY_COLON):
_switch_state(shape11, sprite12)
else:
_switch_state(shape11, sprite10)
func _switch_state(new_shape, new_sprite):
self.current_shape.set_trigger(false)
self.current_shape = new_shape
self.current_shape.set_trigger(true)
self.current_sprite.hide()
self.current_sprite = new_sprite
self.current_sprite.show()
It is also possible to have more than one active collision shape, but you get the idea. With a FSM design, you are sure that at any time, your character will be in the desired state and you won't need to manually .hide()
and .show()
your sprites, or enable and disable your collision shapes.
Secondly, I think it would be easier to use an AnimatedSprite
or an AnimationPlayer
. You will ba able to create several animations (one per attack), to set the animation's duration, and to enable and disable the collisions more easily. You also have signals that trigger at the end of an animation if you need to add more logic.
If you do not want to use either AnimatedSprite
or AnimationPlayer
for the moment, there is in Godot 3.0 the method Input.is_action_just_pressed(action), that could be interesting for you. As the documentation says: Returns true when the user starts pressing the action event, meaning it’s true only on the frame that the user pressed down the button. This is useful for code that needs to run only once when an action is pressed, instead of every frame while it’s pressed.
But I don't know if there is something similar in Godot 2.1.
Hope this helps :)