Hi Everybody,
I’m a beginner with LUA and i’m having some issue with my spinning wheel, when i touch the wheel it follows my finger (correct) but when i leave the screen it stops (not correct) i would like that the wheel keep spinning and slow down stops here is my part of code:
[lua] local wheel = display.newImage(“wheel1.png”, true)
wheel.x = display.contentWidth - 195
wheel.y = display.contentHeight - 268
physics.addBody(wheel,“dynamic”,{bounce=0, friction=0.2, radius=1})
wheel.angularDamping = 0.2
local skull = display.newImage(“skull1.png”, true)
skull.x = display.contentWidth - 190
skull.y = display.contentHeight - 379
local function gameLoop()
angle = wheel.rotation
if wheel.angularVelocity == 0 and angle ~= startingAngle then
--print(angle % 360)
local wedge = math.floor(((angle + 45) % 360) /45) + 1
--print(wedge … " " … wedgeName[wedge])
startingAngle = angle
if movementEnded then timer.performWithDelay(1000,playRound); end
end
end
local function spinObject(event)
local t = event.target
local phase = event.phase
--print("Phase: " … 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
t.x2 = event.x
t.y2 = event.y
local angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
local angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
local rotationAmt = angle1 - angle2
t.rotation = t.rotation - rotationAmt
t.x1 = t.x2
t.y1 = t.y2
elseif (phase == “ended”) or (phase == “cancelled”) then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end
– Stop further propagation of touch event
return true
end
wheel:addEventListener(“touch”, spinObject)
Runtime:addEventListener(“enterFrame”, gameLoop)
physics.start() [/lua]
Thanks for the Help!