GameMaker: Studio

GameMaker: Studio

Statistiken ansehen:
Animating Sprites
Hello! I have a quick question about sprites and animation in GM:S. My only previous work with sprites was in a demo of RPGMaker, but I have the basics down - draw an animation as multiple images, frame by frame, and show them sequentially when certain conditions are met. However, I'm a little unclear on how exactly to implement sprite animations in Studio.

If I have a character sprite, I will probably want it to do multiple things (maybe an animation for standing still, an animation for walking, an animation for jumping/falling, etc.). I've noticed in the help section that you can choose to save a sprite file as a .png animation strip, and I've found ways to make it cycle through all images of the sprite for animations. My question, then, is what is the best form for displaying and maintaining the correct image files for a sprite that has multiple animations? Should I lump all the animations into one sprite file and use a system of checks and variables in my code to determine which parts to cycle through (and if so, is there a simple function for cycling through a set number of images given an image index range and a certain speed at which to display them)? Also, if multiple animations should be lumped into one sprite file, are there any useful tools or tricks experienced members like to use to make sure files for different animations don't get mixed up? Or is it a better practice to make a separate sprite for each animation sequence (one for running, one for jumping, etc.)?

Thank you for reading this and I appreciate the help!
< >
Beiträge 12 von 2
I can think of two good ways, at least two that are better than a "system of checks and variables" in your code.

Obviously one option is making a separate sprite for each sequence, as you suggest. I think this is a good and clean way to have multiple animations. It's easy to switch between them in code (set sprite_index). You can also control the image that's being shown directly (image_index, probably a good idea to set it to 0 when you switch to a new sequence) and the animation speed of the current sprite (image_speed). I don't think there's anything wrong with this if you don't need very fine grained control over your animations.

The other option will give you that fine grained control at the cost of being a little more work to set up. You can create a timeline for each sequence, and then assign it as needed in your code (set timeline_index, timeline_position, and timeline_running). If you do this, it doesn't really matter where your frames are stored as you can just set every single frame individually at a specific time. It's also easy to synchronize animation with other actions using timelines, such as playing sound. Note that if you use this to put all frames in a single sprite, you lose the ability to switch between different size sprites for different animations, which is not a problem with separate sprites.

No matter what you do, you could in theory put all your frames on one sheet, not even necessarily a strip, make up your own way of counting frames and finding them in a sprite sheet, and draw them manually in your draw event using draw_sprite_part or one of the more general forms. It's not actually that complicated and you can still use timelines to control the sequencing. But, it seems like it's not really worth it unless you're using some free sprite sheet you found somewhere and don't want to separate the frames out for playing around with it. You'd also still need a single frame as a separate sprite to make basic collisions etc. work again if you need that.
Kudzu 11. Okt. 2012 um 9:56 
This helps a lot, thank you! I was worried that multiple sprites might be considered inefficient, but it looks like that's actually the best option for now. The tip about using timelines should help, too. Thanks again!
< >
Beiträge 12 von 2
Pro Seite: 1530 50

Geschrieben am: 10. Okt. 2012 um 20:57
Beiträge: 2