Hey!
Need some help here to understand what’s not working in my code…
I got a main.lua that triggers the folowing intro:
local composer = require(“composer”)
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
local function Intro2 ()
local background = display.newImage(“outer-space.png”)
background.y = 130
background.x = centerX
background.alpha = 0
sceneGroup:insert(background)
transition.to( background,{ time=100, alpha=1} )
local story2 = display.newImage(“story_2.png”)
story2.y = centerY
story2.x = centerX
story2: scale (.9, .9)
story2.alpha = 0
sceneGroup:insert(story2)
transition.to( story2, { time=250, alpha=1 } )
local button2 = display.newText( " - Continue - ", 0, 0, “Helvetica”, 18 )
button2.alpha = 1
button2.y = display.contentHeight - 15
button2.x = display.contentWidth - 50
button2:setTextColor(255, 254, 185)
sceneGroup:insert(button2)
local function goAway2(event)
button2: removeEventListener( “tap”, goAway2)
display.remove ( event.target, createPlayScreen )
display.remove(story2)
display.remove (background)
composer.gotoScene (“Play”)
end
button2: addEventListener( “tap”, goAway2)
end
local function createIntro ()
_W = display.contentWidth;
_H = display.contentHeight;
scrollSpeed = .5;
local bg1 = display.newImage(“space_8.png”)
bg1: scale( 1, 1 )
bg1.alpha=0
bg1:setReferencePoint(display.CenterLeftReferencePoint)
bg1.x = -50; bg1.y = _H/2.;
sceneGroup:insert( bg1)
local bg2 = display.newImage(“space_8.png”)
bg2: scale(1, 1)
bg2.alpha=0
bg2:setReferencePoint(display.CenterLeftReferencePoint)
bg2.x = 430; bg2.y = _H/2;
sceneGroup:insert( bg2)
local bg3 = display.newImage(“space_8.png”)
bg3: scale (1,1)
bg3.alpha=0
bg3:setReferencePoint(display.CenterLeftReferencePoint)
bg3.x = 910; bg3.y = _H/2;
sceneGroup:insert( bg3)
transition.to (bg1, {time=1000, alpha=1})
transition.to (bg2, {time=1000, alpha=1})
transition.to (bg3, {time=1000, alpha=1})
local function move(event)
bg1.x = bg1.x - scrollSpeed
bg2.x = bg2.x - scrollSpeed
bg3.x = bg3.x - scrollSpeed
if (bg1.x + bg1.contentWidth) < -400 then
bg1:translate( 480*3, 0 )
end
if (bg2.x + bg2.contentWidth) < -400 then
bg2:translate( 480*3, 0 )
end
if (bg3.x + bg3.contentWidth) < -400 then
bg3:translate( 480*3, 0 )
end
end
Runtime:addEventListener( “enterFrame”, move )
local story1 = display.newImage(“story1.png”)
story1.y = centerY
story1.x = centerX
story1: scale (.9, .9)
story1.alpha = 0
sceneGroup:insert(story1)
transition.to( story1, { time=1500, alpha=1 } )
local button = display.newText( " - Continue - ", 0, 0, “Helvetica”, 18 )
button.alpha = 0
button.y = display.contentHeight - 15
button.x = display.contentWidth - 50
sceneGroup:insert(button)
button:setTextColor(255, 254, 185)
transition.to( button, { time=2000, alpha=1 } )
local function goAway(event)
scrollSpeed = 0
button: removeEventListener( “tap”, goAway)
Runtime:removeEventListener( “enterFrame”, move )
display.remove(event.target, story1)
display.remove(story1)
display.remove (bg1)
display.remove (bg2)
display.remove (bg3)
Intro2 ()
end
button: addEventListener( “tap”, goAway)
end
print(“1”)
createIntro ()
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
…which triggers a menu screen. From the menu screen you can access another module, my options screen (ultrabasic so far it’s for testing):
local composer = require( “composer” )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
local function gotoPlay ()
composer.gotoScene (“Play”)
end
local function gotoStory ()
composer.gotoScene (“Intros”)
end
local m_button = display.newText( “music: ON” , 50, 0, “Helvetica”, 20)
sceneGroup:insert(m_button)
local function backButton ()
back = display.newText( “- BACK”, 50, 0, “Helvetica”, 20 )
back.x=350
back.y=150
back:addEventListener ( “tap”, gotoPlay )
sceneGroup:insert(back)
end
local function storyButton ()
storybut = display.newText( “Story”, 50, 0, “Helvetica”, 20 )
storybut.x = 250
storybut.y=50
storybut:addEventListener ( “tap”, gotoStory )
sceneGroup:insert(storybut)
end
backButton ()
storyButton ()
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
Now in here there’s two active buttons. One to go back to the menu from which we came and the other supposedly should jump to initial intro scene.
I can bounce from main screen to options screen smoothly, but once I click the button to go to intro scene it’s blacks out the screen (exits option) but doesn’t go to the scene I required.
Any idea why? (pls don’t mind the clunky code)