hi friend.
i am working on slide screen story as well as i am putting “menu button” on slide but menu button is not working. i think it is director problem So, i am facing problem previous 10 days please help me…
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 = 10
local top = top or 0
local bottom = bottom or 0
local g = display.newGroup()
if slideBackground then
background = display.newImage(slideBackground, 0, 0, true)
else
background = display.newRect( 0, 0, screenW, screenH-(top+bottom) )
background:setFillColor(0, 0, 0)
end
g:insert(background)
images = {}
for i = 1,#imageSet do
local p = display.newImage(imageSet[i])
local h = viewableScreenH-(top+bottom)
if p.width > viewableScreenW or p.height > h then
if p.width/viewableScreenW > p.height/h then
p.xScale = viewableScreenW/p.width
p.yScale = viewableScreenW/p.width
else
p.xScale = h/p.height
p.yScale = h/p.height
end
end
g: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 contentBounds of button
display.getCurrentStage():setFocus( self )
self.isFocus = true
startPos = touch.x
prevPos = touch.x
–transition.to( navBar, { alpha=math.abs(navBar.alpha-1) } )
elseif( self.isFocus ) then
if ( phase == “moved” ) then
local delta = touch.x - prevPos .lua
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 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
background.touch = touchListener
background:addEventListener( “touch”, background )
– Define public methods
function g:jumpToImage(num)
local i
print(“jumpToImage”)
print("#images", #images)
for i = 1, #images do
if i < num then
images[i].x = -screenW*.5;
elseif i > num then
images[i].x = screenW*1.5 + pad
else
images[i].x = screenW*.5 - pad
end
end
imgNum = num
initImage(imgNum)
end
function g:cleanUp()
print(“slides cleanUp”)
background:removeEventListener(“touch”, touchListener)
end
local tapSound = audio.loadSound( “tapsound.wav”)
local bgm2=audio.loadStream(“bgmusic.mp3”)
Channe2 = audio.play(bgm2, {channel=2, loops=-1} )
audio.setVolume(0.25,{channel=2})
local spkon = display.newImage (“spkon.png”)
spkon.alpha=0
spkon.x =display.viewableContentWidth/25.8
spkon.y = display.viewableContentHeight/1.03
transition.to(spkon,{alpha=1})
g:insert(spkon)
local spkoff = display.newImage (“spkoff.png”)
spkoff.alpha=0
spkoff.x =display.viewableContentWidth/25.8
spkoff.y = display.viewableContentHeight/1.03
transition.to(spkoff,{alpha=1})
g:insert(spkoff)
spkoff.isActive=false
spkoff.isVisible=false
spkon.isVisible = true
spkon.isActive =true
local function muteon(event)
if event.phase == “ended” then
audio.setVolume(0,{channel=22})
audio.play( tapSound )
spkon.isVisible = false
spkon.isActive =false
spkoff.isVisible = true
spkoff.isActive = true
end
end
spkon:addEventListener(“touch”, muteon)
local function muteoff(event)
if event.phase == “ended” then
audio.setVolume(1,{channel=22})
spkon.isVisible = true
spkon.isActive =true
spkoff.isVisible = false
spkoff.isActive = false
audio.play( tapSound )
end
end
spkoff:addEventListener(“touch”, muteoff)
local back2 = display.newImage (“back2.png”)
back2.alpha=0
back2.x=display.viewableContentWidth/7.8
back2.y=display.viewableContentHeight/1.03
transition.to(back2,{alpha=1})
g:insert(back2)
function changeScene(e)
if(e.phase == “ended”) then
target = e.target
local menu = target.menu
print("going to "…menu)
director:changeScene(menu) --it is not going to menu page
end
end
back2:addEventListener(“touch”, changeScene)
return g
end
[import]uid: 87661 topic_id: 15911 reply_id: 315911[/import]