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.


Messages - Farbi

Pages: [1]
1
General / 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)

Pages: [1]