Change Sprite in GML
Started by gamzta, Jul 01 2012 08:07 PM
3 replies to this topic
#1
Posted 01 July 2012 - 08:07 PM
Hello,
I want to change a sprite to a totally different sprite (not a frame in the sprite). What code can I use to do that?
It would start out as obj_0 then want to change it to spr_1 then from there spr_2 in other words, I am using numbers and want to change them along the way.
Thanks
I want to change a sprite to a totally different sprite (not a frame in the sprite). What code can I use to do that?
It would start out as obj_0 then want to change it to spr_1 then from there spr_2 in other words, I am using numbers and want to change them along the way.
Thanks
#2
Posted 01 July 2012 - 08:10 PM
Hello,
I want to change a sprite to a totally different sprite (not a frame in the sprite). What code can I use to do that?
It would start out as obj_0 then want to change it to spr_1 then from there spr_2 in other words, I am using numbers and want to change them along the way.
Thanks
simple
use the code
sprite_index = NewSprite
put that code in the event that changes it
e.x put it in key press 1
then when it press it will change that object sprite
#3
Posted 01 July 2012 - 08:10 PM
sprite_index=whatever_sprite
edit: i typed 1 row slower then robinsblade typed his post XD
edit: i typed 1 row slower then robinsblade typed his post XD
Edited by psycho666, 01 July 2012 - 08:11 PM.
#4
Posted 01 July 2012 - 10:08 PM
I think you misunderstand what he's asking... I think he's saying he has a number in a variable that increases and he wants to change the sprite to the one with that number in it (for example, all sprites begin with "spr_" and there's a variable that's set to 1, later it gets set to 2, etc. and he wants to concatenate the value of the variable to "spr_" and change it to whatever sprite that is)
To do that, there's 3 ways that a lot of people do.
First way is the easiest, but slowest and overall worse way to do it. And that's to use the execute_string() to execute the code "sprite_index=spr_"+ string(whatever variable is set to the number)
Second way is much better, in advance you set an array to all the sprites.
Third way is to write a script, something like
There are other ways of doing it as well...
To do that, there's 3 ways that a lot of people do.
First way is the easiest, but slowest and overall worse way to do it. And that's to use the execute_string() to execute the code "sprite_index=spr_"+ string(whatever variable is set to the number)
Second way is much better, in advance you set an array to all the sprites.
array[0] = spr_0; array[1] = spr_1; array[2] = spr_2; // etc.Then you just do sprite_index = array[whatever variable is set to the number];
Third way is to write a script, something like
// name: get_sprite
switch(argument0){
case 0 : return spr_0;
case 1 : return spr_1;
case 2 : return spr_2;
// etc.
}And then do sprite_index = get_sprite(the variable that is set to the number);There are other ways of doing it as well...
Edited by dannyjenn, 01 July 2012 - 10:10 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











