tutorialPageTitle = nil local tutorialCurrentPage = 0 local tutorialImageProp = nil local tutorialLeftArrow = nil local tutorialRightArrow = nil local tutorialPageTitles = { "Basics", "Controls", "Advanced", "Tips", } local tutorialPageImages = { "art/tutorial/tutorial1.png", "art/tutorial/tutorial2.png", "art/tutorial/tutorial3.png", "art/tutorial/tutorial4.png", } local tutorialPageGfx = {} function tutorialSetCurrentPage( pageNum ) local pageTitle = tutorialPageTitles[pageNum+1] .. " (" pageTitle = pageTitle .. tostring(pageNum+1) .. "/" .. tostring(#tutorialPageTitles) .. ")" tutorialPageTitle:setString( pageTitle ) -- set background image layer:removeProp( tutorialImageProp ) tutorialImageProp:setDeck( tutorialPageGfx[pageNum+1] ) layer:insertProp( tutorialImageProp ) -- set up left/right arrows layer:removeProp( tutorialLeftArrow ) layer:removeProp( tutorialRightArrow ) if pageNum > 0 then layer:insertProp( tutorialLeftArrow ) end if pageNum < (#tutorialPageTitles - 1) then layer:insertProp( tutorialRightArrow ) end end function tutorialSetup() inputCallback = tutorialOnInput local tutorialLeftArrowGfx = MOAIGfxQuad2D.new() tutorialLeftArrowGfx:setTexture( UI_CS_LEFT_ARROW ) tutorialLeftArrowGfx:setRect( 0, 0, 33, 66 ) tutorialLeftArrowGfx:setUVRect ( 0, 0, 1, 1 ) tutorialLeftArrow = MOAIProp2D.new() tutorialLeftArrow:setDeck( tutorialLeftArrowGfx ) tutorialLeftArrow:setLoc( 61, 272 ) tutorialLeftArrow:setPriority( 11 ) local tutorialRightArrowGfx = MOAIGfxQuad2D.new() tutorialRightArrowGfx:setTexture( UI_CS_RIGHT_ARROW ) tutorialRightArrowGfx:setRect( 0, 0, 33, 66 ) tutorialRightArrowGfx:setUVRect ( 0, 0, 1, 1 ) tutorialRightArrow = MOAIProp2D.new() tutorialRightArrow:setDeck( tutorialRightArrowGfx ) tutorialRightArrow:setLoc( 869, 272 ) tutorialRightArrow:setPriority( 11 ) tutorialPageGfx = { } for i, v in ipairs( tutorialPageImages ) do local tutorialOverlayGfx = MOAIGfxQuad2D.new() tutorialOverlayGfx:setTexture( v ) tutorialOverlayGfx:setRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) tutorialOverlayGfx:setUVRect( 0, 0, 1, 1 ) table.insert( tutorialPageGfx, tutorialOverlayGfx ) end local tutorialOverlayGfx = MOAIGfxQuad2D.new() tutorialOverlayGfx:setTexture( BLACK_BOX_IMAGE ) tutorialOverlayGfx:setRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) tutorialImageProp = MOAIProp2D.new() tutorialImageProp:setPriority( 10 ) tutorialCurrentPage = 0 tutorialPageTitle = setupScreenWithTitle( "CONTROLS (1/4)", 11, true, false ) tutorialSetCurrentPage( tutorialCurrentPage ) -- initialize values -- allocate resources -- spin up threads end function tutorialTeardown() layer:clear() for i, v in ipairs( tutorialPageGfx ) do MOAIPSM.unloadTexture( v.textureID ) end -- spin down threads -- clean up resources end function tutorialOnInput( key, isDown ) if key == KEY_CANCEL and not isDown then -- z SFX["MENU_BACK"]:play() changeGameState(GAME_STATE_MENU) elseif key == KEY_LEFT and not isDown then SFX["MENU_MOVE_L"]:play() tutorialCurrentPage = math.max( 0, tutorialCurrentPage - 1 ) tutorialSetCurrentPage( tutorialCurrentPage ) elseif key == KEY_RIGHT and not isDown then SFX["MENU_MOVE_R"]:play() tutorialCurrentPage = math.min( #tutorialPageTitles - 1, tutorialCurrentPage + 1 ) tutorialSetCurrentPage( tutorialCurrentPage ) end end