(solved) sprite_add and asset_get_index

JFitch

Member
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

Member
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);
 
Top