Hello, i am new to the programming and trying to make an android app with corona, but struggling to prepare the skeleton. i guess i can do the next collision and scene things myself but now i am struggling at rotating and moving the object. i have a background and a paperplane over it, i want player to move the paperplane with finger, paperplane will be dragged also paperplane’s header can rotate to the any degrees between 0 to 360 with the direction of player’s finger.
local background = display.newImageRect("resources/background1.jpg",1000,1000)
background.x = display.contentCenterX; background.y = display.contentCenterY
local paperplane = display.newImage("resources/paperplane.png")
paperplane:scale(0.1,0.1)
local function movePlatform(event)
local platformTouched = event.target
if (event.phase == "began") then
display.getCurrentStage():setFocus( platformTouched )
platformTouched.startMoveX = platformTouched.x
platformTouched.startMoveY = platformTouched.y
elseif (event.phase == "moved") then
platformTouched.x = (event.x - event.xStart) + platformTouched.startMoveX
platformTouched.y = (event.y - event.yStart) + platformTouched.startMoveY
elseif event.phase == "ended" or event.phase == "cancelled" then
display.getCurrentStage():setFocus( nil )
end
return true
end
function getAngle(x1,y1,x2,y2)
local PI = 3.14159265358
local deltaY = y1 - y2
local deltaX = x1 - x2
local angleInDegrees = (math.atan2( deltaY, deltaX) * 180 / PI)*-1
local mult = 10^0
return math.floor(angleInDegrees * mult + 0.5) / mult
end
paperplane.x = display.contentWidth/2
paperplane.y = display.contentHeight/2
paperplane.touch = function(self, event)
if event.phase == "moved" then
paperplane.rotation = (getAngle(paperplane.x,paperplane.y,event.x,event.y)+180)*-1
end
end
Runtime:addEventListener("touch",paperplane)
paperplane:addEventListener("touch", movePlatform)
So when i hold the paperplane and drag it, it s dragged but without rotating around. If i hold the paperplane and switching 360 degrees, it s rotating but it stays at his place, doesnt move forward or left etc. I want both happen. It s like a snake game but not with frames, more flexible and can rotate all degrees, not only 90-180-270 like snake, i guess i told my issue. Can you please help me fixing my code or showing me some open source projects that has this qualification i told about ? Thanks.