Hi Everybody,
I’m a Beginner with Corona sdk and Lua, i’m tryng to create a sort of wheel of fortune game, but i’m having trouble with the rotation physics. My wheel rotate when i touch it but stops immediatly after. I would like to give to the wheel a spin effect that slowly decrease the speed just like in the wheel of fortune. Here is my code:
–
– main.lua
–
–
local physics = require(“physics”)
physics.start()
physics.setGravity(0,8)
physics.setDrawMode(“hybrid”)
local background = display.newImage(“background.png”)
background.x = display.contentCenterX
background.y = display.contentCenterY
local arms = display.newImage(“arms1.png”, true)
arms.x = display.contentWidth - 134
arms.y = display.contentHeight - 290
local wheel = display.newImage(“wheel.png”, true)
wheel.x = display.contentWidth - 195
wheel.y = display.contentHeight - 268
physics.addBody(wheel,“static”,{bounce=0, friction=0.2, radius=98})
wheel:applyTorque(3.8)
local skull = display.newImage(“skull1.png”, true)
skull.x = display.contentWidth - 190
skull.y = display.contentHeight - 379
function getAngle(x1,y1,x2,y2)
local PI = 3.14159265358
local deltaY = y2 - y1
local deltaX = x2 - x1
local angleInDegrees = (math.atan2( deltaY, deltaX) * 180 / PI)*-1
local mult = 10^0
return math.floor(angleInDegrees * mult + 0.5) / mult
end
wheel.touch = function(self, event)
print(event.phase)
if event.phase == “moved” then
--If your image is originally pointing to the north use +90
--If your image is originally pointing to the east use +180
--If your image is originally pointing to the south use +270
--If your image is originally pointing to the west use +360 or +0
--My wheel.png is point to the east so I use +180
--You can use this formula
wheel.rotation = (getAngle(wheel.x,wheel.y,event.x,event.y)+180)*-1
end
end
Runtime:addEventListener(“touch”,wheel)
Thanks and i’m sorry for my bad english.