Image textures are not loading to sprite node when the game is exported as apk files.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By muralis923

In my game i am adding some sprite node dynamically when the game is running
and I set the texture property of those newly added sprite nodes.
The game works well in the computer. But when exported to the mobile phone texture [in PNG file formats ] are not loading in to the newly instantiated sprite nodes.

Check your texture naming

PC is not case sensitive but android is

So if there is a mistake in your naming, it might still lead on pc but not on mobile

code | 2021-03-02 16:45

Are you using Directory to look for files?

exuin | 2021-03-03 04:28

The image textures are a series of .png files which are numbered.
First I read the “*.png” files stored in a particular directory using the method Directory.list_dir_begin() of the Directory class.
File name is obtained by using the Directory.get_next() method.
If the file name ends with “.png” then the file name is appended to an Array.
Then this array is used to set the texture property of Sprite node by calling the
load(file_name_array[n]).
The code with above setup works fine in computer.

But when exported to an apk file only files with “.png.import" extension are stored in the “assets” folder. From there those ".png.import” files point to some files with “.stex”
extension.
Even if I use "*.png.import " file names to point to the texture , texture are not loaded.

The sprite gets loaded in the mobile when I load each and every sprite
separately by using the load method without using the array.

var texture = load(“res://An/Ch 1/01.png”)
var ch:Sprite = Sprite.new()
ch.texture = texture
ch.position.x = 99
ch.position.y = 6

But when I use the array to load the texture , The array size itself is zero.
Because no file with “.png” extension is not loaded in to the array.

muralis923 | 2021-03-03 07:19

:bust_in_silhouette: Reply From: exuin

So what you should do is get the file name of the .png.import file, remove the .import part, and then put it into the load function.

Thanks. It worked.

muralis923 | 2021-03-03 07:28

can you explain that in more detail?

I just delete the .import portion of the files?

Synnlaw | 2021-04-12 21:57

Use the directory to look for the import files. Remove the .import from the file name and then put the resulting string into the load function.

exuin | 2021-04-12 23:00