[code]
local function newSlider(params)
local p = params or {}
– local g = display.newGroup()
back = display.newRect(0, 0, p.width or 20, p.height or 300)
g:insert(back)
– back.isVisible = false
back:setFillColor(225,140, 0)
back.strokeWidth = 1
back:setStrokeColor(128, 128, 128)
back.y = 8
button = display.newRect(0, 0, p.buttonWidth or 20, p.buttonHeight or 32)
g:insert(button)
button:setFillColor(139, 0, 0)
button.strokeWidth = 1
button:setStrokeColor(128, 128, 128)
physics.addBody(button,“kinematic”, {density=0, bounce = 0.1, friction = 1})
local leftLimit = back.y + back.width/2
– local leftLimit = 100
local rightLimit = back.y-back.width/2
button.y = leftLimit
g.x = params.x or 10 – x co-ordinate
g.y = p.y or 100 – y co- donate for button
button.x = button.x -1
button.y = button.y + 200
local currentXReading = 100
– local callbackFunc = p.callbackFunc
– local callbackObject = p.callbackObject
button:addEventListener(“touch”, g)
– Nothing much to see here. Just a slider made
– with a backing strip and a square button.
– the slider is passed an object and a function
– to call on that object when the button is moved.
– for simplicity, output values are 0.0 to 1.0
function g:touch(event)
if event.phase == “began” then
display.getCurrentStage():setFocus(button)
elseif event.phase == “moved” then
local movementX = event.y - event.yStart
local posX = currentXReading + movementX
event.target.y = posX
if event.target.y > leftLimit then
event.target.y = leftLimit
elseif event.target.y < rightLimit then
event.target.y = rightLimit
end
local val = event.target.y
– Output value 0.0 … 1.0
– callbackFunc(callbackObject, val / back.width)
elseif event.phase == “ended” then
currentXReading = button.y
display.getCurrentStage():setFocus(nil)
end
return true
end
function g:set(f) – 0.0 … 1.0
button.x = f * button.width
currentXReading = leftLimit + f * back.width
end
return g
end
local slider = newSlider
{
– callbackFunc = setSpeed,
– callbackObject = camera,
}
can anyone help me with this. I would like to be able to scroll the button up and down. I can’t get it to work.
Any help is appreciated [import]uid: 40990 topic_id: 20656 reply_id: 320656[/import]
[import]uid: 52491 topic_id: 20656 reply_id: 81632[/import]