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

Author Topic: Sprite Movement Freezing/Jittering  (Read 1722 times)

0 Members and 1 Guest are viewing this topic.

Lurgypai

  • Newbie
  • *
  • Posts: 6
    • View Profile
Sprite Movement Freezing/Jittering
« on: November 22, 2016, 12:34:57 am »
Hey so, I'm kinda new here, and I've been dinkin' around for a few weeks to try and get the hang of this. I noticed that what I've made so far (a pong clone from this: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx tutorial and another simple program from scratch) had a wierd freezing/jittering every have second or so. I decided to write a new program from scratch to see if it was present there. Sure enough, about every half second or so the sprite would freeze and then update to where it should be. Any ideas? Here's the code for the test program:
// y.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "SFML\Graphics.hpp"


int main()
{
        sf::RenderWindow window(sf::VideoMode(720, 720), "hey");
        sf::Event event;

        sf::Texture texture;
        sf::Sprite sprite;
        texture.loadFromFile("images/box.png");
        sprite.setTexture(texture);
        sprite.setOrigin(sprite.getGlobalBounds().width / 2, sprite.getGlobalBounds().height / 2);
        sprite.setPosition(360, 700);
        while (window.isOpen()) {
                window.pollEvent(event);
                switch (event.type) {
                case sf::Event::Closed:
                        window.close();
                        break;
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        sprite.move(-0.005, 0.0);
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        sprite.move(0.005, 0.0);
                }
                window.clear(sf::Color::Black);
                window.draw(sprite);
                window.display();
        }
        return 0;
}
 


I did some google searching and wasn't able to find a solution. Its probably super simple, sorry in advance for the trouble.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Sprite Movement Freezing/Jittering
« Reply #1 on: November 22, 2016, 02:00:07 am »
What's your OS? What GPU are you running? If NVidia, try disabling multi-threading in the GPU settings.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Lurgypai

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sprite Movement Freezing/Jittering
« Reply #2 on: November 22, 2016, 02:22:31 am »
I have a nvidia geforce I think. Where is multithreading? Does it have anything to do with "thread optimization"? I went into the nvidia control panel and that's all I saw. Thanks for the help!

Update: Also, thread optimization was set to "Auto." I set it to both on and off, and ran the test. Both resulted in no change.

Update: I had to restart my pc for something, and the jittering stopped. I must have had something running that was slowing the pc. Next time I'll check what's running, thanks for the help!
« Last Edit: November 22, 2016, 05:21:04 am by Lurgypai »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Sprite Movement Freezing/Jittering
« Reply #3 on: November 22, 2016, 08:52:18 am »
Yes, I meant thread optimization, couldn't think of the right term yesterday. :D

Glad you could get it fixed (for now).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/