Godot Version
4.3
Question
Hi i am new here from PyGame and i want to create smilar Surface with Rect to my project, so i put Nodes: Sprite and Collisionshape2D into Node: Area2D, but i can not get the True message that the collision is happening. The last line in my code. What should i do?
extends Node2D
var surfaces = []
var surface_ind = 0
func _process(delta: float) -> void:
if len(surfaces) >= surface_ind:
for surface in surfaces:
remove_child(surface)
surface_ind = 0
for i in range(5):
if len(surfaces) == surface_ind:
### SURFACE ###
var image = Image.create_empty(10, 10, false, Image.FORMAT_RGBA8)#Image.load_from_file("res://icon.svg")
image.fill(Color.WHITE)
var texture = ImageTexture.create_from_image(image)
var sprite = Sprite2D.new()
sprite.texture = texture
### RECT ###
var rect = RectangleShape2D.new()
rect.size = Vector2(image.get_width(), image.get_height())
var collisionshape = CollisionShape2D.new()
collisionshape.shape = rect
### AREA = SURFACE + RECT ###
var area = Area2D.new()
area.add_child(sprite)
area.add_child(collisionshape)
area.global_position = Vector2(100 +image.get_width()/2, 100+image.get_height()/2)
print(area.has_overlapping_areas())
surfaces.append(area)
add_child(area)
surface_ind += 1
elif len(surfaces) > surface_ind:
add_child(surfaces[surface_ind])
surface_ind += 1
### if previous area overlap with current ###
print(surfaces[surface_ind-1].has_overlapping_bodies())