I solved the problem by making the function that draws the messages also draw the line in the background and adding to the height y of the line coordinates the equivalent of the distance from the beginning of the message box to its center (as this is always fixed) + the total height of the box