Here is my code:
local square = display.newRect( 100, 100, 50, 50) square:setFillColor( 1 ) function square:touch( event ) if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true self.markX = self.x self.markY = self.y elseif self.isFocus then if event.phase == "moved" then self.x = event.x - event.xStart + self.markX self.y = event.y - event.yStart + self.markY elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus( self, nil ) self.isFocus = false end end return true end square:addEventListener( "touch", square ) local arrow = display.newImageRect("arrow.png",50,50) arrow.x=display.contentCenterX arrow.y=display.contentCenterY
Basically I have a square and an arrow image in the center (may have to get an image of an arrow to make it work)
The user can drag around the square.
What I want it to do:
Like a compass, I want the arrow image to rotate in the direction as the square when the square is being dragged.
How do i do that?
–Edit: Image of arrow is attached
