Hello!
I'm writing a simple game in C# and i'm having some difficulty to calculate the local position of a sprite.
What i'm aiming to achieve:
- Calculate the sprite "local position" relative to the parent.
- When the parent sprite position is changed, the children sprite should be aways following the parent while keeping its relative position.
Example:
Lets assume i have a parent sprite at world position (4, 4) and a children sprite at local position (2, 2)
If the parent sprite world position moves to (5, 5), his children local position should be at (3, 3)
Below is a example code of what i'm trying to make.
Lets assume the parent of this sprite moved and SetPosition was called:
public class Sprite
{
public Sprite parent;
public Point world_position;
public Point local_position;
public void SetPosition(Point new_position)
{
// What should these numbers contain?
this.world_position = ???
this.local_position = ???
}
}