• 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!

(solved) sprite_add and asset_get_index

J

JFitch

Guest
If you create a sprite using sprite_add, is it possible to access it using asset_get_index?

I'm making a game in which the characters that are only available through in app purchases will be stored online so the game won't waste memory on them when they're not usable anyway.

The sprites are named so the character's name, direction (0 through 23), and state (standing, walking, punching, etc.) determine what sprite to use. This is how I set the sprite.
Code:
name = "johnfitch";
facing = 16;
state = "punching";
sprite_index = asset_get_index(name + "_" + string(facing) + "_" +state);
// This sets the sprite to johnfitch_16_punching.
Is there a way to do that with sprites created using sprite_add?
 

FrostyCat

Redemption Seeker
Yes, by manually keeping track of them in a map and then shimming the functionality.

At game start:
Code:
global.loaded_sprites = ds_map_create();
Loading a sprite:
Code:
///sprite_load(fname, imgnumb, removeback, smooth, xorig, yorig)
var spr = sprite_add(argument0, argument1, argument2, argument3, argument4, argument5);
ds_map_add(global.loaded_sprites, filename_change_ext(filename_name(argument0), ""), spr);
return spr;
Getting the sprite:
Code:
///get_sprite_named(name)
if (ds_map_exists(global.loaded_sprites, argument0)) {
  return global.loaded_sprites[? argument0];
}
return asset_get_index(argument0);
 
J

JFitch

Guest
Thanks! I would have never thought of that on my own but I completely understand it.
 
Top