Hi
I'm trying to make two sprites have a parent / child transform "relationship" like in unity
I have the following code:
int main(int argc, char** argv)
{
RenderWindow wind(VideoMode(800,400),"test");
Event event;
Sprite sprite;
Texture text;
text.loadFromFile("C:\\test.jpg");
sprite.setTexture(text);
Transform trans;
trans.translate(100,100);
Transform parentTrans;
parentTrans.translate(100,100);
while(wind.isOpen())
{
while(wind.pollEvent(event) )
{
if(event.type == Event::Closed)
wind.close();
}
wind.clear();
parentTrans.translate(0.01f,0.0f);
//trans.rotate(1.0f);
wind.draw(sprite,parentTrans);
wind.draw(sprite,trans*parentTrans);
wind.display();
}
return 0;
}
When i run it i see 2 sprites.
One being drawn at 100, 100
and another one being drawn 100, 100 offset from its parent transform, just as expected.
And as i translate the parentTrans in the x direction
they are both affected, just as i want.
The problem is when i try to rotate the "child" sprites transform (trans).
When i uncomment the line where it rotates the sprite,
the child sprite does not rotate around itself (as it moves along in the x direction), as i was expecting.
Instead it rotates around the corner of the screen (0,0) in a circle that gets bigger and bigger as i keep translating the parent transform.
I'm guessing this is because i have to set the sprites origin to its position, right ?
but how can i do that? when the sprites own position actually never changes, and i cant do something like:
trans.getPosition()
Is there some way i can get the a sprites position on the screen?
or is there a better solution to this problem?
Thanks in advance