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

Pages: [1]
1
General / How to handle animations properly
« on: August 03, 2014, 08:30:18 pm »
Hello folks,

Some time ago in order to learn how SFML works I wrote my personal version of the game 2048. Today i came back to my code with the idea of going some refactor.. Besides many issues, one the most problematic is how the animation are handled, i really think it may be a better way but i have no idea on how to proceed using SFML.

To animate a Sprite, my app every give time just change the position of the sprite object in order to emulate the motion, it happen in two different steps:

  • A thread runs in background and update the sprite positions continuously, the frequency of the update depends on the sprite 'speed', if i want a quick moving object the position update will happen very frequently
  • The main thread draws the sprite on the rendering window 60 times per seconds

The idea works, since the sprites are animated.. But the effect i think is very poor and my question to you is: How to animate efficiently sf::Sprite object in SFML? Is there any 'proper' way?

For reference:
A video of the game (if you dont want to build everything):
The quality of the video is pretty poor.
Repo for the game: https://github.com/fjanisze/2048.git
Repo for the animation engine only (with a banal demo to test the code): https://github.com/fjanisze/simple_animation_engine.git

Please do not comment the texture quality ecc, i know is everthing ugly :)

Thanks



2
Graphics / sf::Font and sf::Text
« on: December 11, 2013, 02:59:08 pm »
Hello,

There's something i dont understand about how the sf::Font and sf::Text objects works, let's assume that we have two threads, A and B. The thread A load the font in a local variable and then enter a loop in which just draw a text, the text -sf::Text- we can safely assume that is a member variable of a class.

Something like this -pseudocode-:

class foo
{
    sf::Font font;
    sf::Text text;
    sf::RenderWindow window;
public:
    foo();
    void set_text( const string& text );
    void loop();
};

where:

foo::foo()
{
   text.setString("THIS IS A TEXT");
   //Set all the other stuff, like position, color ecc ecc
   std::thread run_me( &f , this ); //Run the the function 'loop' in a separate thread.
}

void foo::loop()
{
    //Load the font
    while( )
    {
        //Bla bla
        window.draw( text );
        //bla bla
        //Wait for a while, this_thread::sleep_for
    }
}

Then we have:

int main()
{
    foo f; //the thread is spawned and 'loop' is running, the window shows 'THIS IS A TEXT'
    //Sleep for 1 sec
    f.set_text("THIS NOT WORK");
   //Continue showing the text
}

Let assume that all the missing code is present, the class 'foo' is thread safe and no dangerous operation are done, the question is how is it possible that the second string printed is not THIS NOT WORK but: "THIS   T".

It looks like the character which are printed in the second case are the one in common with the first string already printed, but no other. Why?

If the first text printed is ABC and i want to print in the second BCD then only BC is printed..

Thanks

Thanks

Pages: [1]
anything