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

Checking sprites stored in variables?

Plisken

Member
Hello. So I have a variable which stores a sprite inside it. How do I check/change the image index of said sprite? I'm using a text engine with face portraits for the characters and what I'm trying to do is make a variable that can check/change the sprite's frame via image_index (I have all the faces stored in one sprite as frames)

I thought I could just create a new variable and set it to the sprites image_index like this:

myportrait = spr_portrait_facce
myface = myportrait.image_index

but I get an error when I try it. am I doing something wrong?
 
You would need to create another variable to hold what image index you are at. then when you draw the sprite you would refer to that image index.

GML:
draw_sprite(myportrait, portrait_image_index, x, y);
 

curato

Member
i have messed some with that concept of a bunch of sprite with the same number of frames but I want to trade them out. I just assign one of them to the object then override the draw even then I draw the sprite I want at the image_index that is being calcuated by the instance by just using the its image_index variable. If something like that works for you then it is a lot less overhead because after the draw event you can just control the animation like any other instance. You can manually put any image index in there you like, but if you are going for smooth animation. You need to match the incrementation of your image index to the frame rate of the game.
 

Plisken

Member
So after an hour or so of digging into the code of the text engine, I think I managed to figured it out. Just had to add a variable to an already existing "draw_sprite" code that was buried inside one of the scripts. Thanks for the replies!
 
Top