how to improve code for color fight game

Godot Version

Replace this line with your Godot version

Question

Ask your question here! Try to give as many details as possible
i have it so the color gets put up or down on z index

i think it may be the problem and im not sure how to improve it
as you can see in this gif sometime its not responsive
color fight

if area.is_in_group(“blueTileGroup”):
area.get_parent().get_children()[0].visible = true
area.get_parent().get_children()[0].z_index += 1
elif area.is_in_group(“redTileGroup”):
area.get_parent().get_children()[0].z_index -= 1

1 Like

If you are using area2d it would be easier to do something like this.

Use on area entered signal for player to detect entering square.

When entered set area color to player color.

#in players script

Var color = #some color(0,0,0)
func on_area_entered(area):
area.set_color(color)

#area2d script
func set_color(color)
 $ColorRect.color = color

Using the collision signals that are there in area2d makes life easier.

So, you’d have your Area2D nodes and they would have a collision shape and a colorrect. So, when you walk over the collision shape the player will send their color to the area2d script, where the color of the ColorRect would be changed.

1 Like