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

Author Topic: C++ unexpected sf::Vertex.position movement  (Read 1249 times)

0 Members and 1 Guest are viewing this topic.

Farbi

  • Newbie
  • *
  • Posts: 1
    • View Profile
C++ unexpected sf::Vertex.position movement
« on: December 17, 2017, 12:40:18 pm »
Hey everyone and thanks for reading,

I'm trying to make an Endless Runner and created a
Quote
vector<TILE*>* tiles = new vector<TILE*>[LANE_HEIGHT] //LANE_HEIGHT is the number of vertical TILEs
TILE is basically a babysitter class for a sf::VertexArray that populates it, applies texture, draws the object and moves the sf::Vertex points (moving is the problem)

I loop through all arrays with
Quote
for (int i = 0; i < LANE_HEIGHT;i++) {
         for (int j = 0; j < tiles.size(); j++) {
            if(tiles[j] != nullptr)
               tiles[j]->move(sf::Vector2f(0.2f,0)); //Framerate is set to 30 to make this clearer
         }
      }

My problem here is that most floats applied to
Quote
tiles[j]->move()
cause the object to 'wiggle', making it look like it's in shallow water.
I first thought it was a rounding error so I went through the whole class and wrapped everything in float(x), no success
I get the right results in numbers but when setting the applied float to
Quote
float(0.1f)
it becomes very clear: The left side of the Vertex is 'being left behind' by the rest and after a couple of frames it's jumping to its wanted position, then repeats
Since every object in the array is doing this and overlaps onto the previous one, the wiggle effect is born

I'm losing my mind.

P.S. I left out the float-wrappers because it didn't help and makes it less readable and 'boldified' the affected parts  :)

Thank you in advance!
Farbi

(click to show/hide)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: C++ unexpected sf::Vertex.position movement
« Reply #1 on: December 22, 2017, 08:37:38 pm »
It's advised to only draw on integer positions, because when a pixel is position between two pixels (float value), then OpenGL has to decide how to draw that pixel. This can lead to issues like blurred content or oddly moving pixels. Due to rounding it might well happen that not everything is moving along uniformly but may seem to speed up/slow down at times, which is usually just noticeable as "wiggle" or stutter.

I'm however not sure if that's the issue you're having. If something repeatedly moves between different values, even though you think, you've changed it, then chances are, that you're code logic is somewhere still wrong.
Use a debugger to see what's going on. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything