I set up a table of squares. They are all coming from the same image. I set them up so that they are presented in a circle. These squares are going to be my hit areas. So when I spin the dial it knows what number it is on. The only way that I know how to do this is manual telling each individual box where to go in the code. I know that there is a cleaner and better way of doing this with making each image unique.
[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
local screenW = display.contentWidth
local screenH = display.contentHeight
local dial1Table = { “1”, “2”, “3”, “4”, “5”, “6”,“7”,“8”,“9”,“10” }
local numbers = display.newImageRect(“numbers.png”,254,247)
numbers.x = 250; numbers.y = 300
local dial = display.newImageRect(“dial.png”,264,267)
dial.x = 250; dial.y = 300
local numbers = display.newImageRect(“numbers.png”,254,247)
numbers.x = 800; numbers.y = 300
local dial2 = display.newImageRect(“dial.png”,264,267)
dial2.x = 800; dial2.y = 300
for i=1,#dial1Table do
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 350; hitSpot.y = 275
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 350; hitSpot.y = 330
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 320; hitSpot.y = 380
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 320; hitSpot.y = 380
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 260; hitSpot.y = 400
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 200; hitSpot.y = 380
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 150; hitSpot.y = 330
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 150; hitSpot.y = 275
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 180; hitSpot.y = 225
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 250; hitSpot.y = 205
local hitSpot = display.newImage(“hitSpot.png”)
hitSpot.x = 320; hitSpot.y = 225
end
local x0 , y0, x1, x2
local function angleBetween(a, b) --returns angle between 2 vectors a and b
local angleA = math.deg(math.atan(a.y/a.x))
local angleB = math.deg(math.atan(b.y/b.x))
print(angleB - angleA)
return (angleB - angleA)
end
local function turn(e)
if e.phase == “began” then
x0 = e.x
y0 = e.y
elseif e.phase == “moved” then
x1 = e.x
y1 = e.y
local vector1 = {x=x0-e.target.x, y=y0-e.target.y}
local vector2 = {x=x1-e.target.x, y=y1-e.target.y}
local angle = angleBetween(vector1,vector2)
if (angle > 90) then
angle = angle - 180
elseif (angle < -90) then
angle = angle + 180
end
e.target.rotation = e.target.rotation + angle
x0 = x1
y0 = y1
elseif e.phase == “ended” then
print(“print where am at”)
end
end
dial:addEventListener(“touch”,turn)
dial2:addEventListener(“touch”,turn)[/lua]
Thanks
Jake [import]uid: 51459 topic_id: 15929 reply_id: 315929[/import]
[import]uid: 3826 topic_id: 15929 reply_id: 58985[/import]
[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR