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

Author Topic: Animated Wackiness  (Read 2821 times)

0 Members and 1 Guest are viewing this topic.

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
Animated Wackiness
« on: September 30, 2009, 01:30:06 am »
I used Hiura's Animated Class with good results. But there is a hiccup when I try to place it into one of my classes. I have a class called wanderbot which has Animated BotImage as a member.

BotImage works fine when it is declared in main() but if I put it in wanderbot and put  

Code: [Select]
Basicbot.BotImage(botgo[UP],0.1f);

to start the animation in main it says.

Code: [Select]
term does not evaluate to a function taking two arguments.


I can take out the code and it compiles fine but the bot animation is jiggling and blurry.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Animated Wackiness
« Reply #1 on: September 30, 2009, 02:56:37 pm »
Can I show the minimal code source that reproduce the problem ? ( I've never saw this. )
SFML / OS X developer

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
Animated Wackiness
« Reply #2 on: October 02, 2009, 08:04:36 am »
Quote from: "Hiura"
Can I show the minimal code source that reproduce the problem ? ( I've never saw this. )


My code is too messy and huge to post but here's a skeleton of the problem.

Code: [Select]
class Wanderbot//Class defining Bot behavior
{
 
       public:  
 

          Animated BotImage;
         int loadimage;


 void alertstatus()
{
if (loadimage==0)
{


      BotImage(botgo[UP],0.1f);
   
      BotImage.SetPosition(500.f, 50.f);
     //animation of bot
        }
}
};




In your code you use

Code: [Select]
 
    Animated boy(go[UP], 0.1f);
 


to set boy's initial direction. When I do the same its fine but if I move my Animated BotImage into a class as you see above the compiler complains. I think because it believes Animated BotImage and BotImage() are two different things. The bot moves around but it jiggles a lot .

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Animated Wackiness
« Reply #3 on: October 02, 2009, 08:18:26 am »
Quote
Code: [Select]
BotImage(botgo[UP],0.1f);

You can't call a constructor like this -- a constructor is only called when an object is constructed ;)

1. First solution: use the initialization list, which is the only place where you can call your member's constructor
Code: [Select]
Wanderbot::Wanderbot() : BotImage(botgo[UP], 0.1f)
{
    ...
}


2. Second solution: if the Animated class is copyable and assignable, you can assign your object a copy of a new instance
Code: [Select]
BotImage = Animated(botgo[UP], 0.1f);

3. Third solution: add an initialization function to the Animated class
Code: [Select]
BotImage.initialize(botgo[UP], 0.1f);
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Animated Wackiness
« Reply #4 on: October 02, 2009, 11:15:28 am »
#1 and #2 will work fine.
You can also do this :
Code: [Select]
BotImage.SetAnim(botgo[UP]);
BotImage.SetFrameTime(0.1f);
BotImage.SetPosition(500.f, 50.f);


 :arrow: http://hiura.tuxfamily.org/online/doc/sf_frame_anim_animated/classes.html
SFML / OS X developer