简体   繁体   中英

Rotate objects in the corona sdk

In my game there are two objects (eyes) and I need to make them turn in the direction where the screen was clicked.I found an example listener on the Internet, but it's for multitouch, and I need onetouch.

system.activate("multitouch")

local touches = {}
local touchIDs = {}

local function detectMultitouch()
    for i = 1, #touchIDs do
        print("#"..i.." "..tostring(touchIDs[i]) .." = "..touches[touchIDs[i]].x..","..touches[touchIDs[i]].y)
    end
end

Runtime:addEventListener("touch",function(event)
    if event.phase == "began" then
        touches[event.id] = {}
        touches[event.id].x = event.x
        touches[event.id].y = event.y
        touches[event.id].coords = display.newText(tostring(event.id).." = "..touches[event.id].x..","..touches[event.id].y,0,0,system.nativeFont,15)
        touches[event.id].coords.x = touches[event.id].x
        touches[event.id].coords.y = touches[event.id].y

        table.insert(touchIDs,event.id)
    elseif event.phase == "moved" then
        touches[event.id].x = event.x
        touches[event.id].y = event.y
        touches[event.id].coords.text = tostring(event.id).." = "..touches[event.id].x..","..touches[event.id].y
        touches[event.id].coords.x = touches[event.id].x
        touches[event.id].coords.y = touches[event.id].y - 20
    elseif event.phase == "ended" then
        touches[event.id].coords:removeSelf()
        touches[event.id] = nil
        table.remove(touchIDs,table.indexOf(touchIDs, event.id))


        detectMultitouch(touches)
    end
end)

How can this be implemented?

My suggestion is to use event.x and event.y to get the touch coordinates. Then you could compare them with the eyes coordinates.

This said it is necessary to have 2 different objects for the white part and the coloured part (sorry I don't know the specific names).

This way the white part stands still and you modify the x and y of the coloured part by specific numbers. These numbers would be different depending on the information you got before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM