主题:  大家帮忙改进一下这个圆形的音量控制器...

andyfl

职务:普通成员
等级:1
金币:0.0
发贴:127
#12002/6/6 2:14:32
大家帮忙分析一下这个圆形的音量控制器,看看怎样能让滑动超过300度后无论再怎样顺时针滑动都不会使精灵旋转,小于0度时无论再怎样逆时针滑动都不会使精灵旋转。从而保证它更像真实的圆形滑钮?
我想了许多办法都不理想...

on mouseDown me
mySprite=sprite(me.spriteNum)
slope1 = the clickLoc - mySprite.loc
myClickAngle = GetAngle (me, slope1)
myPrevAngle = mySprite.rotation
repeat while the stillDown
slope2 = the mouseLoc - mySprite.loc
newAngle = myPrevAngle + getAngle (me, slope2) - myClickAngle
member("show").text=string(newAngle)
if newAngle>0 and newAngle<300 then--设定滑动范围在0度到300度之间
mySprite.rotation=newAngle
sound(8).volume=integer(300/255*mySprite.rotation)
end if
updatestage
end repeat
end mouseDown

on GetAngle me, slope
deltaH = slope[1]
deltaV = slope[2]
if deltaH then
slope = float (deltaV) / deltaH
angle = atan (slope)
if deltaH < 0 then
angle = angle + pi
end if
else if deltaV > 0 then
angle = pi / 2
else if deltaV < 0 then
angle = (3 * pi) / 2
else
angle = 0
end if
angle = (angle * 180) / pi
return angle
end GetAngle