I’m trying to drag + rotate some objects in a game
here is the code i arrived for 1 specific defined object but not working; it works only the drag part of the code.
----- Scivolo DX Drag Move -------------------------------
scivolodx1= display.newImage(“scivolodx001legnoviti160.png”)
screenGroup:insert(scivolodx1)
scivolodx1.x = scivolodx1.contentWidth *1.5 + 30
scivolodx1.y = display.contentHeight - scivolodx1.contentHeight/2 -30
scivolodx1.rotation = 0
physics.addBody( scivolodx1, “dynamic”, physicsData:get(“scivolodx001legnoviti160”) )
scivolodx1.isSleepingAllowed = false
function scivolodx1:touch( event )
if event.phase ==“began” then
display.getCurrentStage():setFocus( self, event.id )
self.isFocus = true
self.markX = self.x
self.markY = self.y
-------------------------------------------test to rotate ( made simple )
elseif self.isFocus then
if event.phase == “stationary” then
self.rotation = self.rotation + 45
end
-------------------------------------------drag touch object
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
----------------------- Limit themoving Object at display size ( or borders defined by other objects)
if self.x < self.contentWidth/2 + BordoSX.contentWidth then
self.x = self.contentWidth/2 + BordoSX.contentWidth
end
if self.x > display.contentWidth - self.contentWidth/2 then
self.x = display.contentWidth - self.contentWidth/2
end
if self.y < self.contentHeight/2 then
self.y = self.contentHeight/2
end
if self.y > display.contentHeight - self.contentHeight/2 - interfaccia1.contentHeight then
self.y = display.contentHeight - self.contentHeight/2 - interfaccia1.contentHeight
end
elseif event.phase == “ended” or event.phase == “cancelled” then
-------------------------- end focus
display.getCurrentStage():setFocus( self, nil )
self.isFocus = false
end
end
---------------------------- event handled
return true
end
– scivolosx1 Touch Event Listener
scivolodx1:addEventListener( “touch”, scivolodx1)
another question is: if have 100 object spawned with a repeated function or a cicle for i = 1, 100
which is the fastest way to build a Function to drag move and rotate the object i put the finger on ?
Thanks in advance