【问题标题】:Measure volume on tap of button轻按按钮测量音量
【发布时间】:2011-08-29 14:17:31
【问题描述】:

嘿,下面是一个在运行时测量音量的代码。我想要一个按钮,当点击一次时会像此代码一样启动音量,然后再次点击时停止测量。

local g = display.newGroup()

local function newBar()
local bar = display.newLine( 0, 0, 1, 0 ) 
bar:setColor( 0, 55, 100, 20 )
bar.width = 7
bar.y=400
bar.x=20
    return bar
end


local volumeBar = newBar()

volumeBar.y =  309
volumeBar.x = 320


function volumeBar:enterFrame ( event )

local v = 20*math.log(r:getTunerVolume())    
local MINTHRESH = 20
local LEFTMARGIN = 20
local ONE = -1
local v2 = MINTHRESH + math.max (v, -MINTHRESH)
v2 = (display.contentWidth - 20 ) * v2 / MINTHRESH
local neg =  math.max ( 20, v2 )
volumeBar.xScale =  neg * ONE
if (v >= -4) then
    volumeBar:setColor( 110,  110, 20, 200 )

elseif (v < -4) then

volumeBar:setColor( 235,  80, 80, 233)

end 

end

Runtime:addEventListener("enterFrame", volumeBar)

g:insert(volumeBar)

请帮忙,因为这里需要点击 2 次。

【问题讨论】:

    标签: android lua coronasdk


    【解决方案1】:

    给按钮添加一个tap事件监听器,在tap函数中调用Runtime:removeEventListener("enterFrame", volumeBar)。

    【讨论】:

    • 好吧,我试过了,它已经不起作用了:(。因此我需要帮助这里的代码。
    • 本地函数 newBar() 本地 bar = display.newLine( 0, 0, 1, 0 ) bar:setColor( 0, 55, 100, 20 ) bar.width = 7 bar.y=400 bar.x=20 返回栏结束
    • 本地volumeBar = newBar() volumeBar.y = 309 volumeBar.x = 320
    • function volumeBar:enterFrame ( event ) local v = 20*math.log(r:getTunerVolume()) local MINTHRESH = 20 local LEFTMARGIN = 20 local ONE = -1 local v2 = MINTHRESH + math。 max (v, -MINTHRESH) v2 = (display.contentWidth - 20) * v2 / MINTHRESH local neg = math.max (20, v2) volumeBar.xScale = neg * ONE if (v >= -4) then volumeBar:setColor ( 110, 110, 20, 200 ) elseif (v
    • 本地buzzL = ui.newButton { defaultSrc = "defence.png" , defaultX = "50" , defaultY = "50", overSrc = "defence-light.png" , overX = "50" ,overY =“50”,onEvent = myButtonHandler,id =“buzzL”}buzzL.x=126buzzL.y=292buzzL:addEventListener(“tap”,buzzer2)buzzL.buzzer2Selected = falsephysics.addBody(buzzL,“静态")
    猜你喜欢
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多