![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Animatect |
Hi, I’m working on a card game, with a certain amount of cards that can change as the development process progresses.
All the card images are in a forlder inside the project, I made a card object which I instance and store dinamically as many times as images I have, and inject the image at creation time using the load() method.
Everything works fine on the editor, but once I Export, the game doesn’t seem to find the images, except the one I manually added to the card object scene as a working reference.
this makes me think that the engine isn’t aware that it should export these resources, I added the .jpg extension an the path/folder/to/images/ to the exporter filters, and made sure that the path to the res folders is correct. how can I export the images to be recognized?
As a side note: when I collect the files using “.jpg.import" in my code’s conditional instead of ".jpg”, it finds the files but can’t iterpret them, which I guess must be normal.
here’s also a bit of the relevant parts of my code. Thank you in advance for your help, I have tried a bunch of things and nothing seems to work.
Collecting the files:
func list_files_in_directory(path:String,extension:String)->Array:
var files:Array = []
var dir:Directory = Directory.new()
dir.open(path)
dir.list_dir_begin()
var safecounter:int = 0
while true and safecounter<500:
var file:String = dir.get_next()
if file == "":
print("safecounter: =" + String(safecounter))
break
elif not file.begins_with("."):
if file.ends_with(extension):
files.append(file)
safecounter+=1
dir.list_dir_end()
return files
Loading the data from the filePaths:
func CreateCards()->Array:
var tempcardspath:Array = list_files_in_directory(cardsDir,"jpg")#jpg.import
print(tempcardspath)
var tempCards:Array = []
for tempcard in tempcardspath:
var thisCard:String = tempcard
var card:Card = cardObj.instance()
var imagePath:String = cardsDir+tempcard
var cardTexture:Texture = load(imagePath)
var cardID:String = (thisCard.split("_",false,1)[1]).split(".",false,1)[0]
card.cardID = cardID
card.cardImage = cardTexture
tempCards.append(card)
#emit_signal("card_created")
return tempCards
paths to card object and to the images:
var cardsDir:String = "res://Art/Cards/MainDeck/"
onready var cardObj:PackedScene = preload("res://Scenes/Card.tscn")
I’m having the same issue as well (godot 3.2.1), I’d be interested to know if you solve it.
Panagiotis Halatsako | 2020-04-24 22:37