I’m using the Slider class found in the code exchange and its very straight forward. As I move the slider back and forth, i’m wanting to show a different image. The problem is, its not erasing the image previously. I’m a newbie so i imagine there is a better more efficent way to code this, but i’m not sure.
Please help as this is the last component to a app framework i’m building.
[code]
module(…, package.seeall)
– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
– Background
local background = display.newImage(“images/background.png”)
localGroup:insert(background)
local displayGroup = display.newGroup()
local mySlider = require(“slider”)
local press = function( event )
print( “press” )
end
local release = function( event )
print( “release” )
end
local eventHandler = function( event )
local chapterGroup = display.newGroup()
local chapterNumber = tonumber(string.format("%." … (idp or 0) … “f”, event.value))
print( “id = " … event.id … “, phase = " … event.phase … " value=” … tonumber(string.format(”%." … (idp or 0) … “f”, event.value)))
if chapterNumber == 1 then
imgCh = display.newImage(“images/Chapter1.png”)
chapterGroup:insert(imgCh)
elseif chapterNumber == 2 then
imgCh = display.newImage(“images/Chapter2.png”)
chapterGroup:insert(imgCh)
elseif chapterNumber== 3 then
imgCh = display.newImage(“images/Chapter3.png”)
chapterGroup:insert(imgCh)
elseif chapterNumber == 4 then
imgCh = display.newImage(“images/Chapter4.png”)
chapterGroup:insert(imgCh)
elseif chapterNumber == 5 then
imgCh = display.newImage(“images/Chapter5.png”)
chapterGroup:insert(imgCh)
end
end
local mySlider = slider.newSlider(
{
track = “images/track.png”,
thumbDefault = “images/thumb.png”,
thumbOver = “images/thumbDrag.png”,
maxValue = 8,
isInteger = true,
onPress = press,
onRelease = release,
onEvent = eventHandler,
}
)
– Title
local title = display.newText(“Touch to go back”, 0, 0, native.systemFontBold, 16)
title:setTextColor( 255,255,255)
title.x = 160
title.y = 240
title.name = “title”
localGroup:insert(title)
– Touch to go back
local function touched ( event )
if event.phase == “ended” then
mySlider:removeSelf()
director:changeScene(“menu”,“fade”)
end
end
background:addEventListener(“touch”,touched)
mySlider.x = display.contentWidth / 2
mySlider.y = display.contentHeight / 2
unloadMe = function()
end
– MUST return a display.newGroup()
return localGroup
end
[/code] [import]uid: 16420 topic_id: 7463 reply_id: 307463[/import]