help please

[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]

You’re limiting the sliding - for example line 21 sets a really low range of movement.

Is that intentional? [import]uid: 52491 topic_id: 20656 reply_id: 81197[/import]

not intentional, changing the a few numbers from from the billy cart code. when I set it higher, the button doesn’t show up on the screen [import]uid: 40990 topic_id: 20656 reply_id: 81273[/import]

Is there a reason you’re using this rather than writing a slightly simpler version? It seems as though you may not fully understand the code and as such have difficulty modifying it - you could make a very simple slider in far less lines by simply making a slider that you can draw only on the Y coord and using a sensor to handle its position.

Is that an option? [import]uid: 52491 topic_id: 20656 reply_id: 81442[/import]

Yes peach. I need some kind of slider
thank you [import]uid: 40990 topic_id: 20656 reply_id: 81483[/import]

Very basic sample, needs tweaking but is a simple starting point;
[lua]local slideBar = display.newRect( 20, 20, 10, 300 )

local slideBtn = display.newRect( 15, 20, 20, 40 )
slideBtn:setFillColor( 100, 100, 255 )

local function slide (event)
if slideBtn.y >= 40 and slideBtn.y <= 280 then
slideBtn.y = event.y
elseif slideBtn.y < 40 then slideBtn.y = 40
elseif slideBtn.y > 280 then slideBtn.y = 280
end
end
slideBtn:addEventListener(“touch”, slide)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 20656 reply_id: 81632[/import]

this works fine. Thanks a lot [import]uid: 40990 topic_id: 20656 reply_id: 81775[/import]

Not a problem :slight_smile: [import]uid: 52491 topic_id: 20656 reply_id: 81809[/import]