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

Author Topic: Sprite animation with inconsistant sprite sizes  (Read 3122 times)

0 Members and 1 Guest are viewing this topic.

CodingNewbie

  • Newbie
  • *
  • Posts: 6
    • View Profile
Sprite animation with inconsistant sprite sizes
« on: October 13, 2013, 07:28:29 am »
Hello everyone.  I'm currently trying to animate a sprite with SFML, but I'm running into an issue because all the guides I can find on it assume that every sprite is the same (16x16, 32x32, etc).  Mine are any 3 of these sizes:
 
 - 60x76
 - 56x76
 - 56x72

Any help with this would be greatly appreciated.  In case any of you are wondering, I attached the sprite sheet I'm using (making a Pallet Town clone from Pokemon Fire Red):



 

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Sprite animation with inconsistant sprite sizes
« Reply #1 on: October 13, 2013, 08:04:36 am »
Why not just add some blank pixels to the pallette until every sprite is the same square size?  That's probably a lot easier than complicating your rendering code to deal with variable-sized sprites.

If you really want variable sizes then you'll just have to write the more complex logic yourself.  You have to define the texture rectangles for each sprite in the sheet anyway, so you should always have access to the current sprite's size and can compute the offsets you want from that.
« Last Edit: October 13, 2013, 08:06:46 am by Ixrec »

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Sprite animation with inconsistant sprite sizes
« Reply #2 on: October 13, 2013, 08:07:47 am »
Why not just add some blank pixels to the pallette until every sprite is the same square size?  That's probably a lot easier than complicating your rendering code to deal with variable-sized sprites.

I completely agree. Remaking your sprite sheet is going to be better/easier than an alternative, which would be hard coding the frames into your game, or maybe putting the frame data in a file and loading that at run-time.
DSFML - SFML for the D Programming Language.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: Sprite animation with inconsistant sprite sizes
« Reply #3 on: October 13, 2013, 08:10:05 am »
Edit: Double ninja-ed...

While it's possible to animate with different sizes, it will take you unessecary more programming and processing time, because you'll most likely have to create your own format that specifies how each frame has to be loaded.
It's on the other hand, far simpler to go and change the spritesheet once before runtime to use fixed sizes, thus allowing for an automated iteration over the texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

CodingNewbie

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sprite animation with inconsistant sprite sizes
« Reply #4 on: October 13, 2013, 02:20:40 pm »
Sounds like a plan!  I wasn't sure how complex the logic would have to be.  Much appreciated gentlemen.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Sprite animation with inconsistant sprite sizes
« Reply #5 on: October 13, 2013, 02:28:56 pm »
By the way, if you don't want to reinvent the wheel, take a look at my implementation in Thor.Animation :)

// Define animation with two frames and their relative durations 1 and 2
thor::FrameAnimation animation;
animation.addFrame(1.f, sf::IntRect(...));
animation.addFrame(2.f, sf::IntRect(...));

// Either directly animate a sprite
sf::Sprite sprite;
animation(sprite, progress);

// Or use animator for convenience
thor::Animator<sf::Sprite, std::string> animator;
animator.addAnimation("walk", animation, sf::seconds(3.f));
animator.playAnimation("walk");
...
animator.update(frameTime);
animator.animate(sprite);

Having frames with different sizes is no problem, just specify it at thor::FrameAnimation.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: