Click flag. Mercury rotates on its axis 3 times for every 2 times it orbits the Sun. This is a 3:2 spin-orbit resonance. With every orbit around the sun Mercury ends up facing the opposite direction.
Mercury's spin has 1.5 times the angular frequency of its orbit. Every other orbit around the sun, Mercury faces up. So that we can have Mercury move in two different ways (spin and orbit), we have Mercury sprite rotate and a use a separate circling sprite to complete orbit. We make Mercury x coordinate matches x coordinate of the circling sprite. No complicated math required.