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

Show Posts

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.


Topics - shadetree

Pages: [1]
1
General / Thor2.0: Linking resource / texture to Animation
« on: February 26, 2015, 07:11:30 am »
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

Pages: [1]
anything