#Adding filles to array
1 messages · Page 1 of 1 (latest)
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"
You could use ResourceLoader instead of direct file access
1Yes theyr only png filles and i pretend to filter to be possible to open only png ones 2.How that? WARNING : when you export your game, your directory will not have the images in it, only the ".import"?? I can only open with the .import ones not the .png ones? How should i proced with that?
TY btw
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
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
i done it like this! any problem doing like this?
i still openend the .png but with load
no erros came back or warnings...
Try to export your game and see if it works
It didn't for me
I have something similar, where I do it like:
var myTexture := load(...) as Texture2D
if myTexture:
# do stuff
I haven't actually tried it with a wrong type of file, but I think it would catch it
dosnt work yop
wheni try to do it the other way gives me this error
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
So I browse the png.import but i load the .png, this is utterly confusing but at least it works
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
You dodged a massive bullet with me noticing your thread, spent a whole day trying to understanding this bug this week
Yop i actually thout in making the .png part but never the remove characters one
this is so stupid lol
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
Yop me too man
Just one thing how would i substitute the res:// ?? because when i export it doesn't create the new image on the inventory per say i am also deleting it and probably bc its using the //res: is not deleting the filles