@Aalok, hereâs an example using mesh:
I wasnât sure what you meant by the zoom, but I put in a slide transition. Tap on the left half to go back, right half to forward.
EDIT: Updated code to work with your test image
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
--comicSections = 3 -- How many sections are in the comic
local parts = {
{ 1 },
{ 0.615, 1 },
{ 1 }
}
comicImg = createImage("Dropbox:TestComic", parts) -- Split image into slides
currentSection = 1 -- What part are we on
sectionSize = 1/comicSections -- How much of the whole image one section takes
transitionTime = 0.5 -- How long the transitions take
comicMesh = mesh() -- Set up the mesh
comicMesh.texture = comicImg
comicMesh:addRect(WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
comicMesh:setRectTex(1, 0, 0, sectionSize, 1)
--autoChange()
end
function autoChange()
tween.delay(2, function() nextSection() autoChange() end)
end
function createImage(imgKey, tbl)
comicSections = 0
for i,v in ipairs(tbl) do
comicSections = comicSections + #v
end
local oldImg = readImage(imgKey)
local newImg = image(WIDTH*2.75, HEIGHT*2.75)
pushStyle()
setContext(newImg)
spriteMode(CORNER)
local rowImg, colImg
local rowHeight = oldImg.height / #tbl
local widthInd = 0
for row,rTbl in ipairs(tbl) do
rowImg = oldImg:copy(0, rowHeight * (#tbl - row), oldImg.width, rowHeight)
for i,curInd in ipairs(rTbl) do
prevInd = rTbl[i - 1] or 0
local width = (rowImg.width * curInd) - (rowImg.width * prevInd)
colImg = rowImg:copy(rowImg.width * prevInd, 0, width, rowHeight)
sprite(colImg, (newImg.width / comicSections) * widthInd, 0,
newImg.width / comicSections, newImg.height)
widthInd = widthInd + 1
end
end
setContext()
popStyle()
return newImg
end
function nextSection()
if currentSection < comicSections then
local time = transitionTime/2
local next = function()
local nextSection = currentSection + 1
local s = 1/comicSections
tween(time, _G, {sectionSize = s, currentSection = nextSection}, tween.easing.linear)
end
tween(time, _G, {sectionSize = sectionSize*2}, tween.easing.linear, next)
elseif currentSection == comicSections then
currentSection = 1
end
end
function prevSection()
if currentSection > 1 then
local time = transitionTime/2
local prev = function()
local s = 1/comicSections
tween(time, _G, {sectionSize = s}, tween.easing.linear)
end
local prevSect, s = currentSection - 1, sectionSize*2
tween(time, _G, {currentSection = prevSect, sectionSize = s}, tween.easing.linear, prev)
elseif currentSection == 1 then
currentSection = comicSections
end
end
function draw()
background(0)
comicMesh:setRectTex(1, 1/comicSections * (currentSection-1), 0, sectionSize, 1) -- Focus on sectio
comicMesh:draw()
end
function touched(touch)
if touch.state == ENDED and sectionSize == 1/comicSections then
if touch.x > WIDTH/2 then
nextSection()
elseif touch.x < WIDTH/2 then
prevSection()
end
end
end