Note that there are some explanatory texts on larger screens.

plurals
  1. POCorona SDK rotation
    primarykey
    data
    text
    <p>I'm working on a project that involves a clock, and a set_alarm mechanism that works by dragging a rotating pointer (clock is classic like analog with pointers, not digital) that is attached to the center of the clock, so by rotating pointer (that sets alarm) you can set the alarm. Here is the source:</p> <pre><code>local function rotateObj2(event) local t = event.target local phase = event.phase if (phase == "began") then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position of finger t.x1 = event.x t.y1 = event.y elseif t.isFocus then if (phase == "moved") then animateAlarm = true t.x2 = event.x t.y2 = event.y angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x) angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x) print("angle1 = "..angle1) rotationAmt = angle1 - angle2 --rotate it t.rotation = t.rotation - rotationAmt print ("t.rotation = "..t.rotation) t.x1 = t.x2 t.y1 = t.y2 alarm.rotation = t.rotation setAlarm.rotation = t.rotation print ("setAlarm.rotation = "..t.rotation) if(alarm.rotation &gt;=0)then local hourValue = math.floor(t.rotation/30) local minuteValue = math.floor(t.rotation*2) local hour = hourValue local minute = minuteValue if(minuteValue&gt;=720 and minuteValue&lt;780)then minute = minuteValue-720 elseif(minuteValue&gt;=660 and minuteValue&lt;720)then minute = minuteValue-660 elseif(minuteValue&gt;=600 and minuteValue&lt;660)then minute = minuteValue-600 elseif(minuteValue&gt;=540 and minuteValue&lt;600)then minute = minuteValue-540 elseif(minuteValue&gt;=480 and minuteValue&lt;540)then minute = minuteValue-480 elseif(minuteValue&gt;=420 and minuteValue&lt;480)then minute = minuteValue-420 elseif(minuteValue&gt;=360 and minuteValue&lt;420)then minute = minuteValue-360 elseif(minuteValue&gt;=300 and minuteValue&lt;360)then minute = minuteValue-300 elseif(minuteValue&gt;=240 and minuteValue&lt;300)then minute = minuteValue-240 elseif(minuteValue&gt;=180 and minuteValue&lt;240)then minute = minuteValue-180 elseif(minuteValue&gt;=120 and minuteValue&lt;180)then minute = minuteValue-120 elseif(minuteValue&gt;=60 and minuteValue&lt;120)then minute = minuteValue-60 end if (hour &lt; 10) then hour = "0" .. hour end if (minute &lt; 10) then minute = "0" .. minute end hourField.text = hour minuteField.text = minute end elseif (phase == "ended") then display.getCurrentStage():setFocus( nil ) t.isFocus = false print ("ENDEDsetAlarm.rotation = "..setAlarm.rotation) end end -- Stop further propagation of touch event return true end </code></pre> <p>The problem is that when I try to define alarm clock value (like 03.45) it's ok. I transform the rotation of the pointer as you can see. But, if the rotation goes below -90 or over 270 i dont get results. That's because i did not define what to do with that (-rotation)</p> <p>PROBLEM:</p> <p>after some time, the rotation shifts. So i dont have rotation = 0 to 270 and -90 to 0, but -90 to -360+(-90) = -450;</p> <p>sometimes it becomes from 60 to 360+60=420</p> <p>WTF IS THAT?! =(</p> <p>help please, i can't get around that, Because these "shifts" seem to happen randomly(or I just cant get why they happen)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload