OK I finally figured out part of it.
SFML shapes have a position that's independent of where the actual shape is. That position is 0,0 by default.
You seem to be under the assumption that the position will be equal to the upper-left corner of the rectangle, which isn't true.
I don't know if this will help... but think of the shape as a sort of piece of transparent paper. The position of that piece of paper is 0,0 (top left of the screen). If you draw a rectangle at 50,50, it will be placed at 50,50 on the paper, but the paper itself is still at 0,0. Moving the paper around with SetPosition() / Move() would of course move the piece of paper (and therefore move the visible shape)
So really, the problem is, GetPosition is giving you the position of the paper, not the position of the shape drawn on the paper. If you want these to be the same, then the shape must be drawn at 0,0, and the paper moved to the desired position.
Change your CObject ctor to something like this:
1 2 3 4 5 6 7 8
|
CObject::CObject(float s, float w, float h, sf::Shape& obj, colRegion col, float x, float y)
: speed(s), width(w), height(h), object(&obj), collision(col), startx(x), starty(y)
{
// note we put it at 0,0,w,h
*object = sf::Shape::Rectangle(0,0,w,h, sf::Color(100, 100, 100));
// then move it to the desired position
object->SetPosition(startx,starty);
}
|
(of course you'll need to update both ctors)
After that it appears to work for me.
Although you have some design issues =x for such a small program it's very messy and confusing.