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

Author Topic: Divide the image into parts for animation.  (Read 2869 times)

0 Members and 1 Guest are viewing this topic.

vechestva

  • Newbie
  • *
  • Posts: 25
    • View Profile
Divide the image into parts for animation.
« on: October 03, 2012, 03:16:49 pm »
Hello! How to divide the image to animate?
Give an example, please.

img example source:

I do not know much English.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Divide the image into parts for animation.
« Reply #1 on: October 03, 2012, 03:24:51 pm »
Look at the wiki, there are ready to use animation classes.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Divide the image into parts for animation.
« Reply #2 on: October 03, 2012, 03:25:37 pm »
Load the image as sf::Texture and then change the TextureRect with setTextureRect to the size of one number and then you can move that TextureRect whenever you need the next animation frame.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vechestva

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Divide the image into parts for animation.
« Reply #3 on: October 03, 2012, 03:30:56 pm »
I do not know much English.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Divide the image into parts for animation.
« Reply #4 on: October 03, 2012, 03:47:38 pm »
Give an example, please.
Do you think we are your code monkeys?  ???

There are examples on how to use sf::Texture in the official tutorials, in the documentation, on the wiki, in the forum, etc...
Open your eyes and use your 'Computer skills' to find them... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

vechestva

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Divide the image into parts for animation.
« Reply #5 on: October 05, 2012, 12:25:20 pm »
Can I set the original "textureRect", without creating an instance?
so I do not like::
sf::IntRect origRect = spite.getTextureRect();
sprite.SetTextureRect(0, 0, 50, 50);

/*
    ....
*/


// return to original
sprite.SetTextureRect(origRect);
 
I do not know much English.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Divide the image into parts for animation.
« Reply #6 on: October 05, 2012, 01:36:58 pm »
No, since there's no such thing as a 'default' rectangle (except if you'd count the [0,0,0,0] one which the sprite gets initialized with).
For animation you should structure the texture in a way that you can only increase one or two value by a constant factor of the rect, so you'd only have to check if the end is reached and things could start again from the beginning.
Alternatively you can also hardcode all the different rects, but that not a very smart solution... ;)

As we've mentioned earlier you should take a look at the already existing animation class in the wiki, so you get the idea better on how to do things. And if you want a nice implementation (and possible more features) you could check out Thor. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/