How do I lock the position of a sprite so that it cannot move outside the white box shown above?
The heart inside the box?
You could use 4 Sprites, one for each side or you could use a tilemap.
Develop games in your browser. Powerful, performant & highly capable.
Couldn't you just clamp it since it's a rectangle?
clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.