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

Author Topic: Animated Sprite class  (Read 28818 times)

0 Members and 1 Guest are viewing this topic.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Animated Sprite class
« Reply #15 on: December 30, 2013, 12:41:46 pm »
Indeed! Nice bug! Thanks for pointing it out. That what happens, when you refractor with copy & paste... I fixed it on the wiki.
As for your example code. I will look at it when I find some time. (I wanted to write a better example since a long time, maybe I'll have some time over the break...)
edit: I had a quick look at your code and this is not how the class is supposed to be used(/extended). I'll try to write a better example soon.
About "stop()" I implemented it just like your CD/MP3 player would: play plays the animation, pause halts/pauses it and stop pauses it and resets it to the beginning. I find it logically that way, but of course you can modify the source in any way that fits your need ;)
« Last Edit: December 30, 2013, 12:57:17 pm by Foaly »

DemonRax

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Animated Sprite class
« Reply #16 on: January 01, 2014, 05:08:50 pm »
Yeah, I'm not saying you should use my example :) That's just the modified version I made for myself. But I thought the bug is quite important.

Funny thing is - it works same way, because it uses m_currentFrame variable when calling  the function and then basically the value is there, so you don't really need internal newFrame :) But when I tried to setFrame manually it made me scratch my head for a while before I've noticed the mistype.

Looking forward for the extended class! Thanks!

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Animated Sprite class
« Reply #17 on: January 02, 2014, 11:00:36 pm »
Luckily I found some time to write up a better example of how to use this class. I fixed yet another bug and uploaded a completly new example. Everybody please take a look at it and tell me what you think. I am open for comments and improvements!

check it out : https://github.com/SFML/SFML/wiki/Source:-AnimatedSprite

damnednforsaken

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Animated Sprite class
« Reply #18 on: March 26, 2014, 06:23:51 pm »
A big class that I don't have to write myself score!
Seriously thank you for writing this tutorial.

Hmm I can't get to seem to get it to work though.

From the wiki I copied pasted, the individual files and made them into files. main,animations,animated sprites

When I run through g++ I get it to compile
g++ -c main.cpp ...........GOOD
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system .........FAIL
So the linking fails,

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
main.o: In function `main':
main.cpp:(.text+0x254): undefined reference to `Animation::Animation()'
main.cpp:(.text+0x26d): undefined reference to `Animation::setSpriteSheet(sf::Textur\
e const&)'
main.cpp:(.text+0x2b1): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x2f5): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x339): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x37d): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x38c): undefined reference to `Animation::Animation()'
main.cpp:(.text+0x3a5): undefined reference to `Animation::setSpriteSheet(sf::Textur\
e const&)'
main.cpp:(.text+0x3e9): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x42d): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x471): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x4b5): undefined reference to `Animation::addFrame(sf::Rect<int>)'
main.cpp:(.text+0x4c4): undefined reference to `Animation::Animation()'
main.cpp:(.text+0x4dd): undefined reference to `Animation::setSpriteSheet(sf::Textur\
etc...

Not sure why, thoughts?

damnednforsaken

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Animated Sprite class
« Reply #19 on: March 26, 2014, 08:45:26 pm »
Ughh... yea, Im dumb..
This was caused by not linking properly. KNOW your compiler/linker!!

Ok, I wasn't compiling all the files for ones so,
instead of
g++-c main.cpp
needed to do
g++ -c main.cpp Animation.cpp AnimatedSprite.cpp

and during the linker stage needed to do,
g++ AnimatedSprite.o Animation.o main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

ughh sorry bout all that.

ImmutableMeta

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Animated Sprite class
« Reply #20 on: February 07, 2015, 01:25:16 am »
So, I have quite a few improvements to suggest, as well as some minor organizational changes I would make. But I think I will just write my own and post it :)

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Animated Sprite class
« Reply #21 on: March 08, 2015, 01:52:12 pm »
Please go ahead and tell us what you would change/improve. New stuff is always welcome!