[as2 port] iPod-style scroll wheel

the calculation works, just not sure why i’ve had to negate the value. If anyone could fix that please?

get the Corona files at: http://www.sendspace.com/file/0eynkx

original code from: http://www.bezzmedia.com/swfspot/samples/flash8/iPod_Style_Wheel_Slider
[lua]-- not needed for Corona - we know it’s pressed in the touch “began”/“moved” phases
– local _pressed = false
local _lastAngle = nil
local _readOut = 0

– centre points
local xpos = display.contentWidth/2
local ypos = display.contentHeight/2

– ipod image
local ipod = display.newImage(“wheel.png”)
ipod.x = xpos
ipod.y = ypos

– readout textfield
local disp_txt = display.newText(“Turn Wheel!”, display.contentWidth/2 - 50, display.contentHeight/2 - 120, native.systemFont, 16)
disp_txt:setTextColor(0,0,0)

– wheel overlay - alpha=0.01 because 0 disables it
local wheel = display.newCircle(xpos-2, ypos+11, 89)
wheel:setFillColor(0,0,0)
wheel.alpha=0.01

– button overlay - alpha = 0.01 beacause 0 disables it
local button = display.newCircle(xpos-2, ypos+11, 33)
button:setFillColor(0,0,0)
button.alpha=0.01

– theres no math.round function, this is equivalent
local function math_round(n)
return(math.floor(n+0.5))
end

– when we touch the scroll ring
local function wheelTouch(event)

if(event.phase==“began”) then

– _pressed = true

elseif(event.phase==“moved”) then

– not needed for Corona, it’s already part of the touch phase
– if(_pressed == true) then

–set the x to the mouseposition minus the center of the wheel
local pressx = event.x-wheel.x ;
–set the y to the mouseposition minus the center of the wheel
local pressy = event.y-wheel.y --*-1;

–calculate the angle from the center of the wheel to the mouse
–local angle = math_round(math.atan(pressy/pressx)/(math.pi/180));

– NOT SURE WHY I’VE HAD TO SUBTRACT THIS
– IT WORKS BUT IF SOMEONE COULD FIX THE MATHS PLEASE!?
local angle = 0-math_round(math.deg(math.atan(pressy/pressx))+90);

if(pressx<0) then angle=angle+180; end
if(pressx>=0 and pressy<0) then angle=angle+360; end

–if the wheel was pressed on the last frame
if(_lastAngle~=nil) then
–this if statement is a fix for when the angle crosses from 0 to 360 or 360 to 0
if(math.abs(_lastAngle-angle)<180) then
–update the counter
_readOut=_readOut + (_lastAngle-angle);
disp_txt.text = tostring(_readOut)
end
end

–store this angle so it can be compared to the angle in the next frame
_lastAngle=angle;

– end

elseif(event.phase==“ended”) then

– _pressed = false
_lastAngle = nil

end

end

– when we tap the cente button
function buttonTap(event)
_readOut = 0
disp_txt.text = tostring(_readOut)
end

wheel:addEventListener(“touch”, wheelTouch)
button:addEventListener(“tap”, buttonTap)[/lua]

[import]uid: 6645 topic_id: 3847 reply_id: 303847[/import]