Try these:
The splashscreen just displays an image until you hit start.
The menuscreen has some movable components: a solid backdrop over the image to provide contrast and a movable selection bar controlled by up/down under a layer of text on transparency. Saving the last state of controls allows it to wait for distinct button presses, rather than just the state which can still be depressed from a previous menu.
Code: Select all
----------------------------------
-- Splash Screen
-- Just display an image until start is pressed
function splashScreen()
splashimg = Image.load("backgrounds/background1.png") -- 480 x 272
while not Controls.read():cross() do
screen:blit(0, 0, splashimg, 0, 0, splashimg:width(), splashimg:height(), false)
screen.waitVblankStart()
screen.flip()
end
end
----------------------------------
-- Menu Screen
-- Display a menu of different options selectable using controls
-- Returns the index of the selected option
-- Possible parameters:
-- background image
-- number of parameters
-- names of parameters
function menuScreen()
local numoptions = 2
local optionnames = {}
optionnames[1] = "Execute"
optionnames[2] = "Edit Mode"
local bgoffx = 100
local bgoffy = 80
local baroffx = 30
local baroffy = 20
local baroffskip = 30
local optiontxtoffx = 5
local optiontxtoffy = 5
-- imaging
local green1 = Color.new(0, 64, 0)
local optionbgcol = Color.new(64, 64, 64)
local optionfgcol = Color.new(255,255,255)
local splashimg = Image.load("backgrounds/background2.png")
local selectbar = Image.createEmpty(100,20)
local optionbg = Image.createEmpty(200,100)
local optiontxt = Image.createEmpty(200,100)
-- paint components colors to their images
optionbg:fillRect(0, 0, optionbg:width(),optionbg:height(), optionbgcol)
selectbar:fillRect(0, 0, selectbar:width(),selectbar:height(), green1)
-- Paint Menu Options to a clear image
for i = 1, numoptions do
optiontxt:print(baroffx + optiontxtoffx, baroffy + baroffskip*(i-1) + optiontxtoffy, optionnames[i], optionfgcol)
end
-- add offsets for moving selection bar
local baroffx = baroffx + bgoffx
local baroffy = baroffy + bgoffy
-- State variables
local selopt = 0
local keep_going = true
local menuPush = Controls.read() -- state of controls
local LastPush = menuPush
while keep_going do
LastPush = menuPush
menuPush = Controls.read()
if menuPush:up() and not LastPush:up() then selopt = math.mod( selopt - 1 + numoptions, numoptions) end
if menuPush:down() and not LastPush:down() then selopt = math.mod( selopt + 1 + numoptions, numoptions) end
if menuPush:cross() and not LastPush:cross() then keep_going = false end
screen:blit(0, 0, splashimg, 0, 0, splashimg:width(), splashimg:height(), false)
-- draw option selector bar under text
screen:blit(bgoffx, bgoffy, optionbg, 0, 0, optionbg:width(),optionbg:height(), true)
screen:blit(baroffx, baroffy + selopt * baroffskip, selectbar, 0, 0, selectbar:width(),selectbar:height(), true)
-- draw option text layer
screen:blit(bgoffx, bgoffy, optiontxt, 0, 0, optiontxt:width(),optiontxt:height(), true)
screen.waitVblankStart()
screen.flip()
end
return selopt
end