Newbie Question, need help!

Hi, I am new to this and was wondering a simple solution to having app which has a circle in the middle that moves with touch (similar to volume dial)

Please look at attachment to get better idea  :) and thanks!

What I have so far:

–> Add Phyiscs engine

local physics = require (“physics”)

physics.start()

system.activate(“multitouch”)

–>Hide status bar

display.setStatusBar(display.HiddenStatusBar)

–> Add Background image

local background = display.newImage(“assets/bkg.png”)

–> Add circle

local circle = display.newImage(“assets/circle.png”)

circle.x= display.contentWidth/2

circle.y= display.contentHeight/2

physics.addBody(circle,“static” )

Cool idea!

I doubt you need the physics module for this (unless you need it for other parts of the code or game).  All you should really need is to add an event-listener to the knob/circle image … and hack out the trig (and corona doesn’t really help here, since some things are in radians and some in degrees).

This seems to work for me:

local rad2deg = 180.0/3.14159265 --\> Add circle local circle = display.newImageRect("circle.png",100,100) circle.x = display.contentWidth/2 circle.y = display.contentHeight/2 function circle:touch( e ) if( e.phase == "began" ) then -- store where we started the touch-event at local dx = e.x - self.x local dy = e.y - self.y self.startAngle = math.atan2( dy, dx ) elseif( e.phase == "moved" ) then -- calc rotation from touch-start local dx = e.x - self.x local dy = e.y - self.y local newAngle = math.atan2( dy, dx ) local da = newAngle - self.startAngle self:rotate( rad2deg\*da ) self.startAngle = newAngle elseif( e.phase == "ended" ) then self.startAngle = 0 end return true end circle:addEventListener( "touch", circle )

Cool idea!

I doubt you need the physics module for this (unless you need it for other parts of the code or game).  All you should really need is to add an event-listener to the knob/circle image … and hack out the trig (and corona doesn’t really help here, since some things are in radians and some in degrees).

This seems to work for me:

local rad2deg = 180.0/3.14159265 --\> Add circle local circle = display.newImageRect("circle.png",100,100) circle.x = display.contentWidth/2 circle.y = display.contentHeight/2 function circle:touch( e ) if( e.phase == "began" ) then -- store where we started the touch-event at local dx = e.x - self.x local dy = e.y - self.y self.startAngle = math.atan2( dy, dx ) elseif( e.phase == "moved" ) then -- calc rotation from touch-start local dx = e.x - self.x local dy = e.y - self.y local newAngle = math.atan2( dy, dx ) local da = newAngle - self.startAngle self:rotate( rad2deg\*da ) self.startAngle = newAngle elseif( e.phase == "ended" ) then self.startAngle = 0 end return true end circle:addEventListener( "touch", circle )