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 sprite moved and called UpdateChildrenPositions with his new position, what should the local and world positions of his childrens be?
public class Sprite
{
public Sprite parent;
public List<Sprite> childrens;
public Point world_position;
public Point local_position;
public void UpdateChildrenPositions(Point new_position)
{
// What should these numbers contain?
this.world_position = ???
this.local_position = ???
}
}
Could someone provide a direct answer with the math to solve this problem?
Thanks in advance!