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

Author Topic: Animation using sftools::Animated  (Read 5319 times)

0 Members and 1 Guest are viewing this topic.

Luinechor

  • Guest
Animation using sftools::Animated
« on: December 21, 2009, 07:55:38 pm »
Hello,

I'm trying to animate my sprites, so I'm using this class: http://www.sfml-dev.org/wiki/en/sources/frame_anim_animated

My game is a simple spaceshooter, so there is a class, which represents different types of an enemy with the following members (and more, but only these are neccessary for the problem):

Code: [Select]
Anim Animation;
Animated Animated;


Now there are asteroids, space ships and more. For example there is a class called Asteroid, which inherits from the enemy class, with the following members
Code: [Select]
static sf::Image Image;

This image is used for all the asteroids, so it's initalized like this: http://www.sfml-dev.org/tutorials/1.5/graphics-sprite.php

Everything works fine while using sf::Sprite instead of sftools::Animated, so there are no problems loading or displaying the sprite/image.

The Animation is initialized in a member function of the Asteroic class:
Code: [Select]
void cAsteroid::InitializeAnimation() {

// first row
Animation.PushFrame(Frame(Image, sf::IntRect(0, 0, 64, 64)));
Animation.PushFrame(Frame(Image, sf::IntRect(64, 0, 128, 64)));
Animation.PushFrame(Frame(Image, sf::IntRect(128, 0, 192, 64)));
Animation.PushFrame(Frame(Image, sf::IntRect(192, 0, 256, 64)));

// second row
Animation.PushFrame(Frame(Image, sf::IntRect(0, 64, 64, 128)));
Animation.PushFrame(Frame(Image, sf::IntRect(64, 64, 128, 128)));
Animation.PushFrame(Frame(Image, sf::IntRect(128, 64, 192, 128)));
Animation.PushFrame(Frame(Image, sf::IntRect(192, 64, 256, 128)));

// last row
Animation.PushFrame(Frame(Image, sf::IntRect(0, 128, 64, 192)));

Animated.SetAnim(Animation);
Animated.Play();
}


If I try to display this animation it just shows nothing. I can shoot the asteroids and get points, but they're invisible.

Image loads without errors. I don't get why the Asteroids are invisible. Any suggestions?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Animation using sftools::Animated
« Reply #1 on: December 22, 2009, 03:57:21 pm »
Can you give us the shortest buildable code that reproduce the problem ?

Did you "Update" and "Draw" four animation ?
SFML / OS X developer

Luinechor

  • Guest
Animation using sftools::Animated
« Reply #2 on: December 22, 2009, 04:39:30 pm »
Quote from: "Hiura"
Can you give us the shortest buildable code that reproduce the problem ?


Uhm, I could comment all the lines which are responsible for the problem and upload the project (it's not _that_ big, because it's my first project). Nevertheless, I'm going to try building a short example which reproduces the problem.

Quote from: "Hiura"
Did you "Update" and "Draw" four animation?


Yes. Just as shown in the wiki.

Thanks for help,
Luinechor

Luinechor

  • Guest
Animation using sftools::Animated
« Reply #3 on: December 22, 2009, 05:01:41 pm »
Okay. I built a small example which reproduces the problem.

It just adds a new asteroid into a vector every half second.

Here's the link to the vc++ 2008 project: http://www.materialordner.de/H5P54IkJip9wtF18LO7gSh4DZ4M3v8l2.html
(You just have to click on: Download von problem.rar)

And here's the main.cpp:
http://paste-it.net/public/f3a662c/

Asteroid.h and cpp
http://paste-it.net/public/a3f3794/
http://paste-it.net/public/lc35c1b/

Enemy.h and cpp
http://paste-it.net/public/w3876f5/
http://paste-it.net/public/idc35a9/

Hope that helps.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Animation using sftools::Animated
« Reply #4 on: December 22, 2009, 05:18:43 pm »
ok.

You're using image (from cAsteroid) in cAsteroid::cAsteroid() before cAsteroid::Init was called.

Try this : http://paste-it.net/public/cd4755e/

(I cannot test, I don't have any SFML installed right now.)
SFML / OS X developer

Luinechor

  • Guest
Animation using sftools::Animated
« Reply #5 on: December 22, 2009, 05:25:21 pm »
Does not work, it's still invisible. Using a 'InitializeAnimation()' function like in my first post (void cAsteroid::InitializeAnimation()) and call it by creating the 'newAsteroid' does not work, either. =/

Update
If I'm not using the vector for the asteroids and just create one (cAsteroid aAsteroid) it works.

Example:
http://paste-it.net/public/g966dda/

ARodrigues

  • Newbie
  • *
  • Posts: 6
    • MSN Messenger - andre_fgr16@hotmail.com
    • View Profile
Animation using sftools::Animated
« Reply #6 on: December 23, 2009, 12:48:35 am »
Hi there,

I'm using the same libs and I have these errors:

Code: [Select]

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall sftools::Frame::Frame(class sf::Image const &,class sf::Rect<int> const &,class sf::Color const &)" (??0Frame@sftools@@QAE@ABVImage@sf@@ABV?$Rect@H@3@ABVColor@3@@Z) referenced in function "class sftools::Anim __cdecl AnimImage(class sf::Image,int,int,int,int,int)" (?AnimImage@@YA?AVAnim@sftools@@VImage@sf@@HHHHH@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall sftools::Frame::Frame(class sftools::Frame const &)" (??0Frame@sftools@@QAE@ABV01@@Z) referenced in function __catch$?_Insert_n@?$vector@VFrame@sftools@@V?$allocator@VFrame@sftools@@@std@@@std@@IAEXV?$_Vector_const_iterator@VFrame@sftools@@V?$allocator@VFrame@sftools@@@std@@@2@IABVFrame@sftools@@@Z$0


in this function:

Code: [Select]


sftools::Anim AnimImage ( const sf::Image& Image, int imgWidth, int imgHeight, int iFrame, int lFrame, int Aux )
{
sftools::Anim anim;
for ( int i = iFrame; i < lFrame; i++ )
{
anim.PushFrame ( sftools::Frame ( Image, sf::IntRect ( ( i * imgWidth ),
  (Aux * imgHeight),
  ( ( i * 1 ) * imgWidth ),
  ( ( i * 1 ) * imgHeight )
) ) );
}
return anim;
}



Can anyone tell me where're the errors? I can't find them  :shock:

Luinechor

  • Guest
Animation using sftools::Animated
« Reply #7 on: December 23, 2009, 03:14:46 am »
Uhm, got it working now. I don't actually know why it does not with the old code, but creating a new cAsteroid in if (Time >= 0.5) and push it back to the vector does not work.

Creating a new Asteroid and initialize a new asteroid at the beginning of the programm does work. So in the if-statement I just calculate a new random position and then push back that new Asteroid, for example:

http://paste-it.net/public/a20307f/

Thanks for the help!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Animation using sftools::Animated
« Reply #8 on: December 23, 2009, 11:08:02 am »
strange...

you can try this one : http://paste-it.net/public/pc4574c/

if it does not work try 2 thing :

first implement all function used by vector ( -> copy constructor, ... I don't remember all the func's )

second remove the static image and create one AFTER the window is created. ( It may have something to do with it. )


-------------
ARodrigues, have you added Frame.cpp to your project ?
SFML / OS X developer

ARodrigues

  • Newbie
  • *
  • Posts: 6
    • MSN Messenger - andre_fgr16@hotmail.com
    • View Profile
Animation using sftools::Animated
« Reply #9 on: December 26, 2009, 03:46:32 am »
Quote from: "Hiura"

ARodrigues, have you added Frame.cpp to your project ?

Sure ^^

 

anything