I’m currently working on a point and click adventure game. now I’m using the storyboard api as well for the level designs. what i need to us have a inventory bar at the bottom that stores the objects i collect while playing the game. this bar should also scroll left and right and needs to be able to select objects in them to use. for example i find a key in the scene1 and click on it. it then goes into my inventory. then i select the key and click on the door. the door unlocks and i can enter into scene2
below are the main.lua file and scene1.lua (first scene of the game)
main.lua file
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
display.setStatusBar( display.HiddenStatusBar )
-- require controller module
local storyboard = require "storyboard"
local widget = require "widget"
-- load first screen
storyboard.gotoScene( "scene1", "fade", 400 )
-- Display objects added below will not respond to storyboard transitions
-- table to setup tabBar buttons
local tabButtons = {
{ label="1", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32, selected=true },
{ label="2", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="3", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
{ label="4", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="5", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
{ label="6", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="7", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
{ label="8", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="9", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
{ label="10", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="11", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
{ label="12", up="assets/graphics/icon2.png", down="assets/graphics/icon2-down.png", width = 32, height = 32 },
{ label="13", up="assets/graphics/icon1.png", down="assets/graphics/icon1-down.png", width = 32, height = 32 },
}
-- create the actual tabBar widget
local tabBar = widget.newTabBar{
top = display.contentHeight - 50, -- 50 is default height for tabBar widget
buttons = tabButtons
}
[[ Uncomment to monitor app's lua memory/texture memory usage in terminal...
local function garbagePrinting()
collectgarbage("collect")
local memUsage\_str = string.format( "memUsage = %.3f KB", collectgarbage( "count" ) )
print( memUsage\_str )
local texMemUsage\_str = system.getInfo( "textureMemoryUsed" )
texMemUsage\_str = texMemUsage\_str/1000
texMemUsage\_str = string.format( "texMemUsage = %.3f MB", texMemUsage\_str )
print( texMemUsage\_str )
end
Runtime:addEventListener( "enterFrame", garbagePrinting )
]]
scene1.lua
---------------------------------------------------------------------------------
-- Covered Porch (100) Room 1
---------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local lastScene = storyboard.getPrevious()
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local background, room2, blackKey, blackdoorlocked, text1
-- Touch event listener for background image
local function gotoRoom2( self, event )
if event.phase == "began" then
storyboard.gotoScene( "scene2", "fade", 400 )
return true
end
end
local function doorlocked( self, event )
if event.phase == "began" then
-- storyboard.gotoScene( "scene20", "fade", 400 )
text1 = display.newText( "Door is Locked, the key should be near by", 0, 245, native.systemFontBold, 20 )
text1:setTextColor( 255 )
transition.to(text1, {time=1000, onComplete = function() display.remove(text1) end})
return true
elseif(event.phase == "moved") then
-- Do Something During the "moved" phase
transition.to(self, {x = event.x, y = event.y, time=0});
end
end
local function onSceneTouchx( self, event )
if event.phase == "began" then
-- i would like to code this to co into inventory , but for testing purposes i have it
-- move into scene3.
-- storyboard.gotoScene( "scene3", "fade", 400 )
return true
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local screenGroup = self.view
background = display.newImage( "assets/graphics/Room1.png", 0, 0 )
screenGroup:insert( background )
blackdoorlocked = display.newImage( "assets/graphics/BlackLock2.png", 175, 0 )
screenGroup:insert( blackdoorlocked )
blackdoorlocked.touch = doorlocked
room2 = display.newImage( "assets/graphics/gotoRoom2.png", 175, 0 )
screenGroup:insert( room2 )
room2.touch = gotoRoom2
blackKey = display.newImage( "assets/graphics/BlackKey.png", 100, 200 )
screenGroup:insert( blackKey )
blackKey.touch = onSceneTouchx
print( "\n1: createScene event")
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
print( "1: enterScene event" )
-- remove previous scene's view
storyboard.purgeScene( lastScene )
print( "last scene was:", lastScene ) -- output: last scene name
-- Update Lua memory text display
blackKey:addEventListener( "touch", blackKey )
room2:addEventListener( "touch", room2 )
blackdoorlocked:addEventListener( "touch", blackdoorlocked )
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
print( "1: exitScene event" )
-- remove touch listener for image
blackKey:removeEventListener( "touch", blackKey )
room2:removeEventListener( "touch", room2 )
blackdoorlocked:removeEventListener( "touch", blackdoorlocked )
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
print( "((destroying scene 1's view))" )
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene
any help would be greatly appreciated
[import]uid: 17701 topic_id: 25560 reply_id: 325560[/import]