Hello!
I've just got Thor 2.0 installed and found myself puzzled at how to point a sprite to it's texture.
Rough example, previously...
sf::Image img;
img.loadfromfile("file.png");
//mask it
sf::Texture tex;
tex.loadfromimage(img);
sf::Sprite sprite;
sprite.setTexture(tex);
sf::intRect *rect;
sprite.setTextureRect(rect); //loop or do whatever rect[i]
i'm not sure how to make sure those animations are over the correct texture. If you had something like...
#define frames 2
sf::IntRect rect[] = {
{0,0,0,0},
{1,1,1,1},
{2,2,2,2}
};
thor::ResourceKey<sf::Texture> key = thor::Resources::fromFile<sf::Texture>("image.jpg");
thor::ResourceCache<sf::Texture> cache;
cache.acquire(key);
std::shared_ptr<sf::Texture> texture = cache.acquire(key);
thor::FrameAnimation Idle;
for (int c = 0; c <= frames; c++)
{
Idle.addFrame(1.f, rect[c]);
}
thor::Animator<sf::Sprite, std::string> animator;
animator.addAnimation("Idle", Idle, sf::seconds(1.f));
.........
animator.play(Idle);
So even though the documentation is really helpful, my understanding of linking the resources to the sprites or FrameAnimations is fuzzy. In theory, the intRect's and texture are there, now how do you tell the program which resource to use it's intRect's over?
VS2013 Express
Windows 7 64bit OS
Latest version of SFML and Thor
Thank you. I've been thumbing through forums and docs while completely missing the examples folder. Since I have your attention, is this runtime error familar to you? Everything should be linked correctly, using the debug libs in debug mode etc.
Error:
(http://s28.postimg.org/nn4ulctfx/assertion.png)
Produced from the following @ animator.playAnimation();
#include <Windows.h>
#include <SFML\Graphics.hpp>
#include <Thor\Animations.hpp>
#include <Thor\Graphics.hpp>
#define frames 6
sf::IntRect rect[] = {
{ 83, 28, 40, 92 },
{ 133, 27, 41, 93 },
{ 183, 27, 41, 93 },
{ 235, 27, 38, 93 },
{ 283, 28, 38, 92 },
{ 332, 28, 39, 92 },
{ 381, 28, 40, 92 },
};
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
sf::Vector2f Screen(600, 400);
sf::RenderWindow window(sf::VideoMode(Screen.x, Screen.y), "Title");
sf::Image img;
img.loadFromFile("img.png");
sf::Color color(159, 82, 159);
img.createMaskFromColor(color);
sf::Texture tex;
tex.loadFromImage(img);
sf::Sprite sprite;
sprite.setTexture(tex);
thor::FrameAnimation Idle;
for (int c = 0; c <= frames; c++)
{
Idle.addFrame(1.f, rect[c]);
}
thor::Animator<sf::Sprite, std::string> animator;
animator.addAnimation("idle", Idle, sf::seconds(1.f));
sf::Clock frameclock;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
}
}
animator.update(frameclock.restart());
animator.playAnimation("Idle", true);
animator.animate(sprite);
window.draw(sprite);
window.display();
window.clear();
}
}
I've seen a few posts here with other people having similar runtime errors but with different references. One suggestion was to rebuild with Cmake, check the examples box and test. I've tried this as well. It's some simple user error surely.
I've never used Thor, but it looks like your problem is that you're mixing lowercase and capital letters.
animator.addAnimation("idle", Idle, sf::seconds(1.f));
animator.playAnimation("Idle", true);
"idle" vs "Idle"
I've never used Thor, but it looks like your problem is that you're mixing lowercase and capital letters.
animator.addAnimation("idle", Idle, sf::seconds(1.f));
animator.playAnimation("Idle", true);
"idle" vs "Idle"
good "eye"! That was the cause of the assertion. It surprisingly didn't enumerate through frames, it was just a still frame. At least now I can tinker and find out why, thank you very much to the both of you.
Again, I've never used Thor so I could be off-base here, but my guess as to why it isn't enumerating through the frames is because you call
animator.playAnimation("Idle", true);
every step in the loop. I'm guessing that is resetting the animation back to the first frame. You probably only want to call it once, and then only call
animator.update(frameclock.restart());
animator.animate(sprite)
every step. Again, this is just a guess though because I don't know Thor and haven't looked at any of the documentation.