#Adding filles to array

1 messages · Page 1 of 1 (latest)

narrow nexus
#

I think your variable "images" is just a string, so you could check that it ends with the expected suffix

bitter snow
#

I do the exact same thing in my game. I just check if the last characters are ".import"

#

If you have more format in your directory, you can check if your file ends with ".png" or ".jpg" or ".svg" and so on instead

#

WARNING : when you export your game, your directory will not have the images in it, only the ".import"

finite edge
#

You could use ResourceLoader instead of direct file access

junior beacon
#

TY btw

bitter snow
# junior beacon 1Yes theyr only png filles and i pretend to filter to be possible to open only p...

I do NOT fully understand the whole thing but here is what I understood:

  • res:// Is not a real directory. It's a virtual directory which IS a real directory when you're in dev but cease to be when you're exported
  • HOWEVER YOU CAN STILL load("res://my_directory/my_image.png") EVEN IF YOU DON'T SEE IT IN THE DIRECTORY IF YOU OPEN IT
  • Therefore you can load it but you can't find it by browsing your directory
  • HOWEVER for some reason you can still see the .import of files you've imported at least once during the developpment (This is the part I don' fully understand)
  • THEREFORE you can load your png basing yourself on the imports you're seing in you directory

Here is my code illustrating this :

    var directory:DirAccess = DirAccess.open("res://images/TABLEAU_RECEPTION")
    var files:PackedStringArray = directory.get_files()
    var i:int = 0
    for file in files:
        #On sélectionne uniquement les .png
        if file.ends_with(".png.import"):
            
            file = file.substr(0, file.length() - 7)
            #Pour chaque png on instancie un sprite auquel on associe la texture
            var myTexture: Texture2D = load("res://images/TABLEAU_RECEPTION/" + file)
            var item:GameItem =  GameItem.new(myTexture)
#

Sorry for my french comments in the code, I work with a french coworker who isn't fond of english

junior beacon
#

Np man i understand a bt of french it was clear

#

Ty for your help i will try to fix it

#

The thing is i am putting images into one fille and then loading them when i instanciate them

#

this part is when i intanciate and then give them the texture of the png on the fille

junior beacon
#

i still openend the .png but with load

#

no erros came back or warnings...

bitter snow
#

It didn't for me

narrow nexus
junior beacon
#

wheni try to do it the other way gives me this error

bitter snow
# junior beacon

Yeah, you'll notice that in my code I remove the 7 last character because I actually want to load the img.png and not the img.png.import even tho the img.png doesn't seems to exist when I check

bitter snow
# junior beacon

So I browse the png.import but i load the .png, this is utterly confusing but at least it works

junior beacon
#

Bra your an god how would i found this online?

#

Ty very much man your an angel

#

I thought wtf hes he removgint he las 7 characters for ashjsahjhjsa

bitter snow
#

You dodged a massive bullet with me noticing your thread, spent a whole day trying to understanding this bug this week

junior beacon
#

Yop i actually thout in making the .png part but never the remove characters one

#

this is so stupid lol

bitter snow
#

HOWEVER I'm still a newbe to Godot, no idea if it's the intended way to code this, I just noticed that it works

junior beacon
#

Yop me too man

bitter snow
#

I suspect that it should be done very differently

#

But I don't know how

junior beacon
#

yhe probably but i was heading the same direction as you

#

Ty bra really ty

junior beacon