Hello, I am new with crown and I have been asked to make a wheel of fortune in which in the sector near the pointer say what color is through an audio, my problem is that I do not know how to capture the value near the pointer to assign the audio and also after I finish the movement I do not know how to do it again to perform the rotation of my wheel
Here is my code
local physics = require("physics") physics.start( ) physics.setGravity(0,0) local cX = display.contentCenterX local cY = display.contentCenterY local rand = math.random local back = display.newGroup() local main = display.newGroup() local background = display.newImageRect( back,"images/background.jpg", display.contentWidth, display.contentHeight ) background.x,background.y = display.contentCenterX, display.contentCenterY local pointer = display.newImageRect(main,"images/pointer.png", 50,50) pointer.anchorY = 0 pointer.x = display.contentCenterX pointer.y = display.contentHeight-display.contentHeight\*0.8 local wheel = display.newImageRect(main,"images/wheel.png", 300,300) wheel.x = display.contentCenterX wheel.y = display.contentCenterY wheel:toBack() physics.addBody(wheel,"dynamic",{density=0.5, friction=0.8, bounce=0.0, radius=110 }) wheel.angularDamping = 0.8 local startTime local perimetro = 2\*math.pi\*110 local numeros={1,2,3,4,5,6,7,8,9,10,11,12} local punto = display.newImageRect( main, "images/punto.png", 100, 100 ) punto.x, punto.y = cX, cY physics.addBody( punto, "static") punto:toBack( ) local pivotJoint = physics.newJoint("pivot", punto, wheel, display.contentCenterX, display.contentCenterY) local color local function crearNumeros() for i=1,#numeros do local numeroTabla = display.newText( main, numeros[i], 1, 1, native.systemFont, 30 ) numeroTabla.x = wheel.x numeroTabla.y = wheel.y - 105 color = "amarillo" if (i == 2) then numeroTabla.x = wheel.x + 50 numeroTabla.y = wheel.y - 90 color = "amarillo-naranjo" elseif(i == 3)then numeroTabla.x = wheel.x + 90 numeroTabla.y = wheel.y - 60 color = "naranjo" elseif(i == 4)then numeroTabla.x = wheel.x + 105 numeroTabla.y = wheel.y color="naranj-rojo" elseif(i == 5)then numeroTabla.x = wheel.x + 90 numeroTabla.y = wheel.y + 60 color = "rojo" elseif(i == 6)then numeroTabla.x = wheel.x + 50 numeroTabla.y = wheel.y + 90 color= "rojo-violeta" elseif(i == 7)then numeroTabla.x = wheel.x numeroTabla.y = wheel.y + 105 color = "violeta" elseif(i == 8)then numeroTabla.x = wheel.x - 50 numeroTabla.y = wheel.y + 90 color = "azul-violeta" elseif(i == 9)then numeroTabla.x = wheel.x - 90 numeroTabla.y = wheel.y + 60 color = "azul" elseif(i == 10)then numeroTabla.x = wheel.x - 105 numeroTabla.y = wheel.y color = "azul-verde" elseif(i == 11)then numeroTabla.x = wheel.x - 90 numeroTabla.y = wheel.y - 60 color = "verde" elseif(i == 12)then numeroTabla.x = wheel.x - 50 numeroTabla.y = wheel.y - 90 color = "amarillo-verde" end physics.addBody( numeroTabla) local weld = physics.newJoint( "weld", wheel, numeroTabla, 100, 100 ) --numeroTabla.isVisible=false end return numeroTabla end 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) if (numeroTabla.x\>wheel.x-20 or numeroTabla.x\<wheel.x+20)then print("color:"..color) end 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 startTime = event.time --print("start time " .. startTime) elseif t.isFocus then if (phase == "moved") then 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 elseif (phase == "ended") or (phase == "cancelled") then local deltaTime = event.time - startTime wheel:applyAngularImpulse( 100000 + rand(33000)) wheel:removeEventListener("touch", spinObject) --print("delta time " .. (event.time - startTime)) movementEnded = true display.getCurrentStage():setFocus( nil ) t.isFocus = false end end -- Stop further propagation of touch event return true end wheel:addEventListener("touch", spinObject) crearNumeros() Runtime:addEventListener("enterFrame", gameLoop) physics.start()