Topic was automatically imported from the old Question2Answer platform.
Asked By
Mate_Dev
extends Area2D
var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
func _on_Player_Laser_area_entered(area):
if area.is_in_group("enemies"): #ignore this
area.take_damage(1). #ignore this
queue_free() #ignore this
randomize()
var item
item = list[rand_range(0, list.size())]
print(round(rand_range(0, list.size())))
So, there’s not really a need to have an Array with the values 0, 1, 2, etc. since those are already the indices of the Array. Instead, the values should be the images themselves. So like:
var list = [preload("image0.png"), preload("image1.png"), preload("image2.png")...
Also how do i can show the different images in a random order in the screen when something is destroyed.
func onPlayerLaserarea_entered(area):
if area.is_in_group(“enemies”):
area.take_damage(1).
queue_free() #when it destroy to show a ramdom image in a random place
Also you can create a dictionary and use load to reduce the use of memory, but impacting performance. Check what fits better for you and read documentation about preload and load before trying this solution.