Hi everyone,
I am working on my very first project in LUA (or any other language for that matter) and decided to make a very linear text based adventure for android. I am having an issue with scrollviews in storyboard. The first scene loads fine, but when i use a button to move to the second scene, all of the text for the first scene is still in the background and can still be moved independently of the new scene. I took the example from the sample app for reference and have just added to it.
–
– scene1.lua
–
local widget = require( “widget” )
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
–
– NOTE:
–
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
–
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local function scrollListener( event )
local phase = event.phase
print( phase )
local direction = event.direction
– If the scrollView has reached it’s scroll limit
if ( event.limitReached ) then
if ( “up” == direction ) then
print( “Reached Top Limit” )
elseif ( “down” == direction ) then
print( “Reached Bottom Limit” )
elseif ( “left” == direction ) then
print( “Reached Left Limit” )
elseif ( “right” == direction ) then
print( “Reached Right Limit” )
end
end
return true
end
local scrollView = widget.newScrollView
{
left = 0,
top = 20,
width = display.contentWidth,
height = display.contentHeight,
scrollWidth = 465,
scrollHeight = 670,
friction = 0.972,
listener = scrollListener,
backgroundColor = {0,0,0}
}
–Create a large text string
local thisText = “SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…SCENE ONE TESTING SCROLLING…”
–Create a text object containing the large text string and insert it into the scrollView
local sceneObject = display.newText( thisText, 0,20, 250,1000, “Times New Roman”, 20)
sceneObject:setTextColor( 255,255,255 )
sceneObject:setReferencePoint( display.TopCenterReferencePoint )
sceneObject.x = display.contentCenterX
scrollView:insert( sceneObject )
local option1 = widget.newButton
{
width = display.contentWidth,
height = 59,
label = “SCENE2”,
onRelease = goBack,
onPress = function()
storyboard.gotoScene( “scene2”,“fade”,400 );end,
}
option1.x = display.contentWidth - option1.width/2
option1.y = sceneObject.contentHeight - option1.height/2
scrollView:insert( option1 )
local option2 = widget.newButton
{
width = display.contentWidth,
height = 59,
label = “YOU DIE HAHA”,
onRelease = goBack,
}
option2.x = display.contentWidth - option2.width/2
option2.y = sceneObject.contentHeight + option1.height - option2.height/2
scrollView:insert( option2 )
-----------------------------------------------------------------------------
– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.
-----------------------------------------------------------------------------
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-----------------------------------------------------------------------------
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-----------------------------------------------------------------------------
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-----------------------------------------------------------------------------
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
-----------------------------------------------------------------------------
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
-----------------------------------------------------------------------------
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
-----------------------------------------------------------------------------
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