Here is my config.lua:
[lua]
application =
{
content =
{
width = 768,
height = 1024,
scale = “zoomeven”,
imageSuffix =
{
["@2"] = 2,
}
},
}
[/lua]
The image files for the outfits are:
“head” images - 768 X 382
“dress” images - 768 X 265
“legs” images - 768 X 274
Here is the slideView.lua file which is called like this:
slideViewHead = slideView.new( myHeads , nil, headTop, 265, callBackFromSlider)
[lua]
module(…, package.seeall)
function new( imageSet, slideBackground, top, slideHeight, callback )
local screenW, screenH = display.contentWidth, slideHeight
local viewableScreenW, viewableScreenH = display.viewableContentWidth, slideHeight
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, 0
local imgNum = nil
local images = nil
local touchListener, nextImage, prevImage, cancelMove, initImage
local background
local imageNumberText, imageNumberTextShadow
local imageDirectory = “images/girls/”
local pad = 20
local top = top or 0
local bottom = bottom or 0
local g = display.newGroup()
background = display.newRect( 0, 0, screenW, screenH )
background:setFillColor(110, 110, 0, 0)
g:insert(background)
images = {}
for i = 1,#imageSet do
local fileName = imageDirectory … imageSet[i]
print( fileName )
local p = display.newImage( fileName )
local h = viewableScreenH
g:insert§
--print(“yScale=”…tostring(p.yScale))
--print(“xScale=”…tostring(p.xScale))
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
imgNum = 1
g.x = 0
g.y = top
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
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 cancelTween()
if prevTween then
transition.cancel(prevTween)
end
prevTween = tween
end
function nextImage()
print( “in nextImage” )
print( swishSound )
audio.play( swishSound, fxChannel )
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)
callback(g)
end
function prevImage()
audio.play( swishSound, fxChannel )
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)
callback(g)
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)
--print( pad )
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
print( "imgnum is " … imgNum )
print( "imagefile is " … imageSet[imgNum]:sub(-6))
end
function tapListener()
print(“in the tap event”)
--storyboard.hideOverlay()
--make sure there is not a sound already playing
if audio.isChannelPlaying( soundChannel ) or soundMode == “None” then
--don’t do anything
else
testChannel = audio.play( girlSound, soundChannel )
end
end
background.tap = tapListener
background:addEventListener( “tap”, background )
background.touch = touchListener
background:addEventListener( “touch”, background )
------------------------
– Define public methods
function getImageNumber( nameIn )
if nameIn:sub(1,4) == “head” then
print(“its a head”)
if #nameIn == 9 then
return tonumber(nameIn:sub(5,5))
else
return tonumber(nameIn:sub(5,6))
end
else
print(“not a head”)
return 0
end
end
function g:getSkinTone()
print(“The image number is:”…getImageNumber( imageSet[imgNum] ))
local imageNumber = getImageNumber( imageSet[imgNum] )
if imageNumber == 4 or imageNumber == 7 or imageNumber == 9 or imageNumber == 15 or imageNumber == 16 or imageNumber == 18 or imageNumber == 27 then
return “tan”
elseif imageNumber == 11 or imageNumber == 2 or imageNumber == 8 or imageNumber == 19 or imageNumber == 33 or imageNumber == 35 or imageNumber == 36 or imageNumber == 43 or imageNumber == 21 then
return “Asian”
elseif imageNumber > 0 then
return “peach”
else
return “n/a”
end
end
function g:isHead()
print(imageSet[imgNum]:sub(1,4))
if imageSet[imgNum]:sub(1,4) == “head” then
return true
else
return false
end
end
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
end
end
--print( pad)
imgNum = num
initImage(imgNum)
end
function g:cleanUp()
print(“slides cleanUp”)
background:removeEventListener(“touch”, touchListener)
end
function g:getCurrentImage()
return imgNum
end
return g
end
[/lua]