1
General / Re: Unresolved External Symbols
« on: October 06, 2016, 04:44:41 pm »
Instead of linking sfml-main.lib I had set main as the entry point which caused all the linker errors. Thanks for the help.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I'm suprised your code doesn't crash instantly...Thanks, unfortunately the wiki is down at the moment, but I made texture and animation both members of the class, and now the animation works I noticed that, in your Animated Sprite class, you declare a "setFrameTime" function in the header file, but never define it in the source file. As I used this function, it caused a linker error, so I added it in:
I think the problem is that your texture and the animation go out of scope at the end of your activate method. AnimatedSprite only takes references to both the texture and the animation, so both have to stay alive for as long as you want to use the AnimatedSprite. This behavior is similar to sf::Sprite. There is also a notice on the wiki page explaining this...
So the easiest fix would be to make texture and animation members of your class.
I am always happy to see my class being useful and to see it in action.I made a simple animation test project using your class and the same sprite sheet, and it works, but trying to use it in my game does not work. Running the game results of one of 3 results:
Please post a complet and minimal code of what is not working. Without that I can't help you…
Have you checked the return value of loadFromFile?
Unhandled exception at 0x003013EF in Game.exe: 0xC0000005: Access violation reading location 0x0000004F.It points to this line in AnimatedSprite.cpp, in the setFrame function:
Unhandled exception at 0x590765CE (sfml-graphics-2.dll) in Game.exe: 0xC0000094: Integer division by zero.It points to this line in AnimatedSprite.cpp, in the draw function:
I also wrote an animation class. It's free and on the wiki. If you want you can use it directly or as a inspiration if you want.Ah, thanks. If I replace sizeof(frames) with 8 (which is how many frames I actually have), the animation fully loops. I will definitely switch to using a spritesheet though, and I might use your animation class, at least for now
I also noticed something weird in your code. In the constructor of Animtion you set currentFrame to -1 and then you set the texture to the first element in the texture vector. In the update() method you increment the currentFrame variable (in this case to 0) and then you set the texture to the vector element with that index. So in the first run you see the first frame twice.
And like Gobbles said you should look into spritesheets (i.e. having all frames of one animation in a single file), because texture switching is a costly operation on the GPU.
edit: Also another important thing: sizeof does NOT return the number of element in an array!!! (In your case you actually fill the vector with 192 textures!!!) It shows how much memory the given variable or type uses in byte. There is a way to determin the number of elements (sizeof(FILE_PLAYER) / sizeof(FILE_PLAYER[0])), but this is C style and you should really rethink the way you load the textures... (for example the return value of loadFromFile isn't checked either...)
sf::Texture texture;
texture.loadFromFile(FILE_PLAYER);
Animation animation;
animation.setSpriteSheet(texture);
for (int i = 0; i < 8; ++i)
{
int width = 16;
int height = texture.getSize().y;
animation.addFrame(sf::IntRect(width * i, 0, width, height));
}
player = new AnimatedSprite(sf::milliseconds(30));
player->setAnimation(animation);