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 - ConnorJW

Pages: [1]
1
Graphics / Managing multiple animations
« on: December 03, 2015, 01:49:14 am »
Hey all,

I'm working on a project at the moment which visualises sort algorithms to demonstrate how they differ in handling the sort problem. This requires a lot of on-screen animation, but vitally, takes in no user input. I'm pretty new to SFML, so I was wondering what's the best approach to handling the animation of each element on the screen?

The elements (each are sprites), will be moved one after another to show the process of sorting. Then once sorted, the sprite will be highlighted green; this has already been implemented. The problem is with all the animations playing at the same time, apposed to first animation, pause, second animation, pause etc...

Originally I though of using threads (coming from a currency programming background), but the SFML tutorials suggest to not use threads to handle graphics. So would you suggest using state machines to achieve this?

Any document/references will be most helpful - or your opinion on how you would go about implementation.

2
Graphics / [Solved] Update function for re-drawing sprite
« on: December 02, 2015, 03:43:28 am »
The current update function should be moving the sprite to the left 10 pixels every time it's called, but the sprite (cup1Sprite) is static and not moving. I tried using sprite.rotate(); and the sprite rotated every frame (which was expected), so something is wrong with the way I've written the update function for updating the sprite position. Can anyone suggest what's going wrong?

Code:
DrawCups.h

    class DrawCups
    {
    public:
        DrawCups(sf::RenderWindow& window);
        ~DrawCups();
   
        void update();
   
        void drawCup1();
   
    private:
        sf::RenderWindow& _window;
        //Cup1
        sf::Texture _cup1;        // the texture which will contain our pixel data
        sf::Sprite _cup1Sprite;         // the sprite which will actually draw it
    };

Update function in DrawCups.cpp

 
   void DrawCups::update()
    {
        sf::Vector2f pos = this->_cup1Sprite.getPosition();
        pos.x+=10;
        this->_cup1Sprite.setPosition(pos);
    }

main.cpp

   
 int main()
    {
        sf::RenderWindow window(sf::VideoMode(1366, 768), "Sorting Algorithm Visualisation: SFML");
        window.setFramerateLimit(60);
        DrawCups drawToWindow(window);
   
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
   
                drawToWindow.update();
   
                window.clear(sf::Color::White);
                drawToWindow.drawBench();
                drawToWindow.drawCup1();
                window.display();
        }
   
        return 0;
    }

Pages: [1]
anything