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

Legacy GM Animated sprite in the Text Box

S

shostifrosty

Guest
Hello everybody!

I'm learning the basics of programming with GMS through some tutorials, and I found one pretty nice for making the dialogues in a RPG. The tutorial included adding the text box and the image of the character speaking (but without animation).

The point is that I want the character to actually speak – moving the lips and all – with an animated sprite, but for the life of me I can't figure out how to do it. When I run the game, it will show just the image still.


I tried to call an object instead of a sprite, but it does incredibly weird things (like drawing another object instead of the one which was supposed to be).

Could anyone take a look at the code and give me a hint on what I'm doing so terribly wrong?

code_sample.JPG
 

Jakylgamer

Member
one thing to note when dealing with sprites in an object.
1 - the objects image_index value / max number of sprites in the assigned sprite is the "MAX" images it will animate through.
example:
say the assigned sprite to the object (from drop down in object properties) has only 1 sub image
the draw_sprite(spritename,image_index,x,y) will only draw the first sub image even though the draw_sprite sprite has 2 or more.

and as a side note:
your draw_sprite(global.face,0,x-300,y+53) will only display the first image because you set the second argument to 0 (use image_index to allow animation to play)
but this only works if the assigned sprite is the same number of sub images as the sprite you want to animate. ( as i tried to explain in the example )

a "work around" way of animating a second sprite would be to make the assigned sprite have multiple sub images of the same sprite /same number of sub images as face sprite (so it doesnt appear to animate but it is)
or just assign the face animation to a variable and use that for the image_index value in draw_sprite()

personally the variable option will give you more control over the animation so i would suggest that one

hope i explained that well enough .
 
S

shostifrosty

Guest
You're such a life saver! Thank you very much.I tried the first solution and it just worked! But, as you mentioned, the work around doesn't work exactly as I wanted (because each animation has different frames it is behaving weird, making the animations start from the middle). I think I'm going to look into this variable solution. Do you happen to know a good tutorial about variables that could be nice for me to check out?
 
Z

Zephyr Schwarzwolf

Guest
If the sprite has one single sub-image, the variable solution seems to be really useful. But if there are different sub-images with a number bigger than one, I suggest you to use the simple image_index. Otherwise, it will "behaving weird" as you say. :D
Note that if your object has an assignated sprite, you can use sprite_index instead of "spritename" in your draw_sprite function.
About variables, that's not really hard. A variable is a way to give another name to something. It makes your code clearer and easier to handle.

There are only four types of variables :
Code:
// 1 : Local variables with this form :

var variable = "whatever you want";
// To be used in the same portion of code ! (If it's used in a script called from one other portion of code, you can, obviously use it in that second code too !)

// 2 : Instance variables with this form :

variable = 0; // Set the variable. If you don't do that, it will say "Not set before reading it" and won't work.
varible = "whatever you want";
// To be used in the same object/instance or its childs !

// 3 : Global variables with this form :

global.variable = 0;
global.variable = "whatever you want"
// To be used... Everywhere ! :D

// 4 : Variables that are already in the code, like y, x, depth, room_height, etc... Don't have to be set to be used everywhere !
Note that variables are REALLY useful in debug mode to display any "invisible" value you want to check in real time. I always have a "watch" variable to be used in the debug mode !
If you want to know more about variables, check for any tutorial about GML you can find online ! Variables are used so often that you will probably learn about them at the same time !
I hope I helped ya ! :p
 
Last edited by a moderator:
S

shostifrosty

Guest
Actually it was really helpful, thank you SO much! Now I really understand better the basics of variables. I'll catch some nice tutorial online to build a solid knowledge about it and start messing up with the code, and then let's see if I can make it work! :D:D:D
 
Z

Zephyr Schwarzwolf

Guest
Sounds great if it works for ya ! ;P Happy to see it was helpful ! :D
 
Top