I've been fighting with this for a few hours now, and I can't figure it out. I ended up making a bunch of debugging textures just to see what was going on, and I finally realized that sf::Sprite and sf::VertexArray think that position (0.f, 20.f) is different.
My vertex array is a 4 vertex Quad where the texture coords are the image corners, and the position coords are the image corners which are supposed to be offset by getPosition(), but when I call setPosition(0.f, 20.f) (which does indeed set the sf::Vertex::position value to (0.f, 20.f) it draws at (0.f, 40.f).
If I set the position to (0.f, 0.f) then it draws at (0.f, 0.f).
The Sprite is as simple as it can be. Load a texture of a small red rectangle, then set it's position to (0.f, 20.f).
The result is the following image (forum image links are apparently broken):
https://imgur.com/a/7Sizy6qWhy is this happening? I'm not using setScale() anywhere in my code. If I set the position of the sf::VertexArray to (0.f, 10.f) then it lines up, so it's screaming scaling error, but I am not setting a scale anywhere at any time.
How do I get sf::VertexArray coords of (0.f, 20.f) to draw 20 pixels down from the top of the window? Thanks.
edit: Apparently if I remove the line "states.transform *= getTransform();" from draw() it puts the vertex array in the correct position. Why would this cause the issue? isn't setting the transform on the renderstate required?
edit2: Apparently removing the aforementioned line breaks all over transformations like scaling, which makes sense. How the hell do you set the position of a transformed entity?!
edit3: Ugh, I finally figured it out. I really wish things like "Don't account for position in your position code" were more clear with SFML.