• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Add ico as sprite using code

Assassin

Member
I am trying to add an ico file as a sprite in my game, during runtime. Trying to do this using sprite_add does not seem to work, the variable that should contain the index for the sprite remains -1. I am able to add it as a sprite through the interface with the import function though. Does that mean not all filetypes you can add as sprites using the interface, you can add using the sprite_add command, or am I doing something wrong? Is there any way I can import an ico file as a sprite within the game code?
 

chamaeleon

Member
sprite_add() documentation states it will load png, gif, and jpeg files. I'd assume ico files therefore are not supported in this way.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Why do you want to import specifically an .ico file? Does .png not work for your purposes?
 

Assassin

Member
What I wanted to do was make the player collect the programs stored on their PC. So I wanted to collect the different icons on their PC and show them in the game, for the player to interact with. Was hoping there would be an easy way to get this done, but seems it's not really possible at the moment.
 

Joe Ellis

Member
Icon files contain either png's or bmp image files (several for each size), and it's not that hard to extract them. You just need to read the data at the start of the file that tells you where the image files are (the offset and size), then you can just rip them out using buffer_copy.
There's info on the format here:
https://en.wikipedia.org/wiki/ICO_(file_format)

For png images you just need to extract them from the icon file into a separate buffer, then save it, then load it using sprite_add.
Bmp images would be quite hard though cus you'd have to make your own function that reads the color data and there are several different versions of the format with different color depth, paletted, compression, bitmask(for the transparency) etc. So it'd be a lot of work to make it support all types of bitmaps. However icons have used pngs since windows vista so there probably aren't many files that would have a bitmap icon.
 
Top