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

GameMaker Sprite_merge

boi513

Member
Is it possible to fill the requirements of this function with variables instead of the direct sprite name?

I have a script that is called in the step event if the character is supposed to have glasses on.

Code:
 var tspr

tspr[0] = sprite_duplicate(gear);                                  //should equal spr_bifocals
tspr[1] = sprite_duplicate(curr_sprite);                        //should equal spr_head
sprite_merge(tspr[0], tspr[1]);
end_sprite = tspr[0];
sprite_delete(tspr[1]);
This code returns a cannot draw non existing sprite in the draw event
posted below

Code:
sprite_index = asset_get_index(end_sprite)


draw_self();


shader_reset();
 
Last edited:

CloseRange

Member
end_sprite is a refrence to a sprite. Not the name of the sprite. You should be able to just say this:
Code:
sprite_index = end_sprite;
 

boi513

Member
end_sprite is a refrence to a sprite. Not the name of the sprite. You should be able to just say this:
Code:
sprite_index = end_sprite;
When I remove "asset_get_index", I get an error that reads "unable to convert string "spr_head" to integer
 

CloseRange

Member
how do you set the variable end_sprite in the create event and do you ever set end_sprite to anything else at any other point?
Also are you calling your script in the right place / at all.
 

boi513

Member
how do you set the variable end_sprite in the create event and do you ever set end_sprite to anything else at any other point?
Also are you calling your script in the right place / at all.
end_sprite has a default sprite which should be spr_head. it is called in the create event.
The script is called in the step event. first the step event checks if the glasses are on, if so then the script is supposed to start
end sprite is supposed to be different if hes not wearing his glasses, but no code is needed for that because the no glasses sprite is spr_head which is the default of end_sprite
 

rytan451

Member
Your problem is this: you're setting end_sprite to "spr_head", not spr_head. The difference is that one is a string, and the other is a sprite reference.
 
Top