Rotate an image between two display objects

How do I rotate the image between 2 display objects?  I would have preferred to use a line instead but I need to put an image. This what I currently have:

lHzXU0y.png

Thsi is what I want:

uojrTUJ.png

I jsut need a formula for the image rotation if anyone can point me in the right direction~

Here you go, I’ve tested this and it works:

local image1 = display.newImageRect("square.png", 50, 50) image1.x, image1.y = 50, 300 local image2 = display.newImageRect("square.png", 50, 50) image2.x, image2.y = 300, 50 --get the angle that the line needs to be rotated to local dx = image1.x - image2.x local dy = image1.y - image2.y local angle = math.deg(math.atan2(dy, dx)) --set how long the line should be local lineLength = math.sqrt((dx \* dx) + (dy \* dy)) --draw the line and rotate it local imageLine = display.newImageRect("line.png", lineLength, 10) imageLine.x, imageLine.y = image2.x + (dx \* 0.5), image2.y + (dy \* 0.5) imageLine.rotation = angle

@Alan QuizTix OMG sir! Sorry for the late reply. Thanks a lot for this, this is exactly how I want it!~

Here you go, I’ve tested this and it works:

local image1 = display.newImageRect("square.png", 50, 50) image1.x, image1.y = 50, 300 local image2 = display.newImageRect("square.png", 50, 50) image2.x, image2.y = 300, 50 --get the angle that the line needs to be rotated to local dx = image1.x - image2.x local dy = image1.y - image2.y local angle = math.deg(math.atan2(dy, dx)) --set how long the line should be local lineLength = math.sqrt((dx \* dx) + (dy \* dy)) --draw the line and rotate it local imageLine = display.newImageRect("line.png", lineLength, 10) imageLine.x, imageLine.y = image2.x + (dx \* 0.5), image2.y + (dy \* 0.5) imageLine.rotation = angle

@Alan QuizTix OMG sir! Sorry for the late reply. Thanks a lot for this, this is exactly how I want it!~