How can I use Slide Viewer in Director?

Hi every one,

I am new in Corona and I found Director Class very usefull. But I want to know how can use Slide Viewer inside it? I used it but Unfortunately it dosn’t removed or cleaned up when I return to the first screen!

Slide Viewer link: http://developer.anscamobile.com/code/slide-viewer

thanks in advance,

Ali [import]uid: 41548 topic_id: 7501 reply_id: 307501[/import]

BUMP :slight_smile:
would like to know too… :confused:
Anyone? [import]uid: 44010 topic_id: 7501 reply_id: 32128[/import]

solved :slight_smile:
i’ve copied the code of slideview inside my scene (not with require), and changed the goup g to loacgroup:
[lua]–SLIDEVIEW-------
local screenW, screenH = 768, 1024
local viewableScreenW, viewableScreenH = display.viewableContentWidth, display.viewableContentHeight
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight

–local viewableScreenW, viewableScreenH = display.viewableContentWidth, display.viewableContentHeight
–local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight

local imgNum = nil
local images = nil
local touchListener, nextImage, prevImage, cancelMove, initImage
local background
–local imageNumberText, imageNumberTextShadow

function new( imageSet, slideBackground, top, bottom )
local pad = 0
local top = 0
local bottom = bottom or 0

–local g = display.newGroup()
background = display.newRect( 0, 0, 768, 820 )
background:setFillColor(0, 0, 0, 0)
localGroup:insert(background)
–g:insert(background)

images = {}
for i = 1,#imageSet do
local p = display.newImage(imageSet[i])
local h = 1100

localGroup:insert§

if (i > 1) then
p.x = screenW*1.5 + pad – all images offscreen except the first one
else
p.x = screenW*.5
end

p.y = h*.5

images[i] = p
end

local defaultString = "1 of " … #images

imgNum = 1

–g.x = 0
–g.y = top + display.screenOriginY

function touchListener (self, touch)
local phase = touch.phase
–print(“slides”, phase)
if ( phase == “began” ) then
– Subsequent touch events will target button even if they are outside the stageBounds of button
display.getCurrentStage():setFocus( self )
self.isFocus = true

startPos = touch.x
prevPos = touch.x

elseif( self.isFocus ) then

if ( phase == “moved” ) then

if tween then transition.cancel(tween) end

–print(imgNum)

local delta = touch.x - prevPos
prevPos = touch.x

images[imgNum].x = images[imgNum].x + delta

if (images[imgNum-1]) then
images[imgNum-1].x = images[imgNum-1].x + delta
end

if (images[imgNum+1]) then
images[imgNum+1].x = images[imgNum+1].x + delta
end

elseif ( phase == “ended” or phase == “cancelled” ) then

dragDistance = touch.x - startPos
print("dragDistance: " … dragDistance)

if (dragDistance < -40 and imgNum < #images) then
nextImage()
elseif (dragDistance > 40 and imgNum > 1) then
prevImage()
else
cancelMove()
end

if ( phase == “cancelled” ) then
cancelMove()
end

– Allow touch events to be sent normally to the objects they “hit”
display.getCurrentStage():setFocus( nil )
self.isFocus = false

end
end

return true

end

function setSlideNumber()
print(“setSlideNumber”, imgNum … " of " … #images)
end

function cancelTween()
if prevTween then
transition.cancel(prevTween)
end
prevTween = tween
end

function nextImage()
tween = transition.to( images[imgNum], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( images[imgNum+1], {time=400, x=screenW*.5, transition=easing.outExpo } )
imgNum = imgNum + 1
initImage(imgNum)
end

function prevImage()
tween = transition.to( images[imgNum], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
tween = transition.to( images[imgNum-1], {time=400, x=screenW*.5, transition=easing.outExpo } )
imgNum = imgNum - 1
initImage(imgNum)
end

function cancelMove()
tween = transition.to( images[imgNum], {time=400, x=screenW*.5, transition=easing.outExpo } )
tween = transition.to( images[imgNum-1], {time=400, x=(screenW*.5 + pad)*-1, transition=easing.outExpo } )
tween = transition.to( images[imgNum+1], {time=400, x=screenW*1.5+pad, transition=easing.outExpo } )
end

function initImage(num)
if (num < #images) then
images[num+1].x = screenW*1.5 + pad
end
if (num > 1) then
images[num-1].x = (screenW*.5 + pad)*-1
end
setSlideNumber()
end

background.touch = touchListener
background:addEventListener( “touch”, background )

end

local myImages = {
“level1.png”,
“level1.png”,
“level1.png”,
“level1.png”
}

new( myImages )[/lua] [import]uid: 44010 topic_id: 7501 reply_id: 32402[/import]

Nice work, but I still can’t do more than 10 or so images on an iPad 1. [import]uid: 7845 topic_id: 7501 reply_id: 32468[/import]

Can you copy/paste the full code of the scene? [import]uid: 7845 topic_id: 7501 reply_id: 32482[/import]

there is nothing more in my code concerning the slideview.
It’s embeded in a Director class like this:
[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()

YOUR CODE HERE

return localGroup
end[/lua]
Somewhere in the code i have a button to pass to a scene:
[lua]local btplay = display.newImageRect( “btplay.png”, 194, 80)
btplay.x = 384
btplay.y = 880
btplay.scene = “level1”
localGroup:insert(btplay)

function changeScene(e)
if(e.phase == “ended”) then
TextCandy.CleanUp()
–display.remove(myImages)
director:changeScene(e.target.scene, “fade”)
end
end
btplay:addEventListener(“touch”, changeScene)[/lua]
[import]uid: 44010 topic_id: 7501 reply_id: 32640[/import]