How this is meant to work:
>I creat a variable for a previouse page, a current page and a next page using tables anc concatenation string functions
>The page number will be a variable "n" which is increased or decreased when I press "x" and "z" respectively
>The next page is held in a canvas and so is the previouse page while the current page is on screen
>This acts as a buffer so when I use the page navigators z and x the images are easily loaded on the screen
Here is my (as real as possible) code.
Code: Select all
function love.load()
--note: all pages must be named as numbers e.g "3.png" not "page3.png"
n = 0 --initial page number
xn = toString(n+1) --next page number
xp = toString(n-1) --previouse page number
if xp == "-1" then
xp = "0"
end
--limits xp to 0 so they are no negative numbers
ext = ".png" --the image file extension
page = {} --creates page as a table
page.next = love.graphics.newImage(xn .. ext) --next page is loaded here
page.prev = love.graphics.newImage(xp .. ext) --previouse page is loaded here
page.num = toString(n)
page.now = love.graphics.newImage(page.num .. ext) --current page is loaded here
end
Code: Select all
function love.keyreleased(key)
--EDIT: added an "and" to limit n not to be negative
if key == "z" and (n > 0) then --previouse navigator
n = n - 1
num = toString(n)
xp = toString(n-1) --updates n and xp on key release
end
if key == "x" then --next navigator
n = n + 1
num = toString(n)
xn = toString(n+1) --updates n and xn on key release
end
end
Code: Select all
function love.draw()
--draw page.now to screen
--draw page.prev to a canvas.prev
--draw page.next to a canvas.next
end
But I'm a little confused on how to do this last part even after reading on Canvas functions.