Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Question on Animation Handling  (Read 1532 times)

0 Members and 1 Guest are viewing this topic.

Sinclaire

  • Newbie
  • *
  • Posts: 2
    • View Profile
Question on Animation Handling
« on: January 18, 2016, 12:32:40 am »
Hello!  :DI have a Question regarding using Sprites for animation. I have heard that libraries such as Thor have good Animation handling and if you tell me it would be best to use it, I will do so. However, because I want to learn, I dont want to simply go down the easiest path. So I hope you can answer me this.

Let's say I want to make a charakter walk to the right and having his Sprite change accordingly to make an animation of the character walking. The way I see it there are three methods to achieve this:


1st Method: Have lots of differend Images (e.g. Character1.png, Character2.png,....) and Change the Sprite of the character continuously from the beginning image to the ending image and repeat.


2nd Method:
Have one huge Image that contains all of the Characters poses needed for the animation and just have his sprite be a small rectangle that envelops one of these poses. So all you need to change for the animation is the position of the rectangle while the image/texture can stay the same. This sounds a lot smarter than the first version.


3rd Method:
Have many different images like in Method 1, but also create many sprites ready. Each of the Sprites contains one Image of the Characters Walking Process, So you simply have to tell the Gamewindow to draw a different Sprite each Time.


I hope to have managed to explain clearly what I mean, because I fear it's not very understandable. So the tl.dr is:
1) One Sprite, many Images. Keep loading different Images as Texture into the one sprite.
2) One Sprite, one Image. Just change the position of the rectangle and thus change how the sprite looks.
3) Many Sprites, each with their own image/texture. Display a different sprite each time.


Instinctively, it sounds like Method 2 is the smartest by far, because it doesnt need too much space for all the Sprites or computation time for reloading Images. But I would be really glad over a definite answer.

Cheers, Sinclaire  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: Question on Animation Handling
« Reply #1 on: January 18, 2016, 01:54:05 am »
One texture containing all the animation frames and one sprite which move about the texture with the texture rect.

I suggest you take a look (again?) at the Sprites & Textures tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Question on Animation Handling
« Reply #2 on: January 18, 2016, 02:47:29 am »
In agreement with eXpl0it3r, option 2.

Some reasons the others are less preferable:
1) Changing textures can be slower.
3) Many sprites means having a separate object per animation frame. Pair that with them all having separate textures, and you get the same things as for method 1. Making them use the same texture would help that though.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*