Legacy GM Help Changing Image index in Draw Event

D

dawson2223

Guest
Hey quick question,

I'm trying to change the index of a UI sprite. I put it in the draw event, and tried changing it in the step event but I'm not sure if GameMaker allows you to change sprites like this.

Code:
//Draw GUI Event

draw_sprite(spr_slayerlevel,0,58,52);
Code:
// Step Event

with (spr_slayerlevel) if (global.Round = 2){
image_index = 1;
}

I'm just trying to switch the sprite's index. tried using sprite_index and that didn't work either. How do I fix this?

Thanks
 

jo-thijs

Member
Change this:
Code:
//Draw GUI Event

draw_sprite(spr_slayerlevel,0,58,52);
to this:
Code:
//Draw GUI Event

draw_sprite(spr_slayerlevel,-1,58,52);
and this:
Code:
// Step Event

with (spr_slayerlevel) if (global.Round = 2){
image_index = 1;
}
to this:
Code:
// Step Event

if (global.Round == 2)
    image_index = 1;
You were telling in the draw GUI event to draw image 0 of the sprite, despite what the value of image_index may be (that's the meaning of the second argument).
Using -1 tells GameMaker to use the value of image_index instead.

You also cannot use sprite indices as parameters for with structures,
you need to either use a keyword, such as noone or all,
or you need to use an object index or an instance id.
Randomly throwing a sprite index in there will just confuse GameMaker and WILL cause unexpected behaviour.
 
D

dawson2223

Guest
Change this:
Code:
//Draw GUI Event

draw_sprite(spr_slayerlevel,0,58,52);
to this:
Code:
//Draw GUI Event

draw_sprite(spr_slayerlevel,-1,58,52);
and this:
Code:
// Step Event

with (spr_slayerlevel) if (global.Round = 2){
image_index = 1;
}
to this:
Code:
// Step Event

if (global.Round == 2)
    image_index = 1;
You were telling in the draw GUI event to draw image 0 of the sprite, despite what the value of image_index may be (that's the meaning of the second argument).
Using -1 tells GameMaker to use the value of image_index instead.

You also cannot use sprite indices as parameters for with structures,
you need to either use a keyword, such as noone or all,
or you need to use an object index or an instance id.
Randomly throwing a sprite index in there will just confuse GameMaker and WILL cause unexpected behaviour.

thank you for the information!
 
Top