SFML community forums
Help => Graphics => Topic started by: Jarwulf 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
Basicbot.BotImage(botgo[UP],0.1f);
to start the animation in main it says.
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.
-
Can I show the minimal code source that reproduce the problem ? ( I've never saw this. )
-
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.
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
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 .
-
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
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
BotImage = Animated(botgo[UP], 0.1f);
3. Third solution: add an initialization function to the Animated class
BotImage.initialize(botgo[UP], 0.1f);
-
#1 and #2 will work fine.
You can also do this :
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