GameMaker How do I get the sprites texture

Azenris

Member
How can I check a building vertex buffer if the texture isn't the same and a break is needed.

I was supplying a function with sprite_get_texture( _spr, _num ), and storing a global, checking if its new.

However I noticed that every sprite had a different ID. I checked with
show_debug_message( "spr="+_spr_name+" tex="+string( sprite_get_texture( _spr, _num ) ) );

Output all my sprites. Every sprite was different.

I guess I misunderstood sprite_get_texture ?
I assumed since all my sprites are on 1 texture page, it would return the same value for all my sprites.

Is there another way to test if a sprite is on the texture page of another?

TY for any help :p Anyway, bedtime, I'll be on tommoz !
 

obscene

Member
Yeah, I asked the same question once. sprite_get_texture is unique to each sprite to be used by shaders and such. What you want is the texture group, and there is not a way in GM to get it. It's disappointing and confusing considering the help uses the same word "texture page" that it uses when describing the pages of texture groups leading you to believe two sprites on the same texture page would return the same texture page ID. But nope.
 
L

Lonewolff

Guest
What if you assign the sprites to a particular texture groups? This way you'll know what sprites are on what texture page.
 

rytan451

Member
Unfortunately, that doesn't solve the problem of programmatically finding which texture page a sprite is part of.
 

Azenris

Member
I havnt fully tested it, but there is texturegroup_get_sprites. Still gotta add the texturegroup names to the array. But I think this will work? Texturegroups are always on the same page? I think.

Code:
var _num_sprites = 0;
while ( sprite_exists( _num_sprites ) )
    ++_num_sprites;

global.sprite_texturegroup = array_create( _num_sprites, noone );

var _texture_groups = [ "Default", "Forest", "Desert" ];
var _texture_group_count = array_length_1d( _texture_groups );

for ( var _tg = 0; _tg < _texture_group_count; ++_tg )
{
    var _tex_array = texturegroup_get_sprites( _texture_groups[ _tg ] );
    var _tex_array_count = array_length_1d( _tex_array );

    for ( var _i = 0; _i < _tex_array_count; ++_i )
    {
        global.sprite_texturegroup[ _tex_array[ _i ] ] = _tg;
    }
}
Should solve what I wanted anyway. If its a different texturegroup from the current. I need to update the texture.
 
Last edited:

obscene

Member
Oh wow... great find. I'd hunted for something like this before, definitely a newer addition. That should work. I'm eager to test this out myself later. Been wanting to add this ability to my debugger for years.
 
Top