Hey guys and ladies, i’ve got a major glitch in my game, especially with storyboard
when i’m on my menu screen with all of the options ,such as play, options and credits, when i press play, it still has some of the properties from the menu scene when i go to the play scene “playing the game part”, such as the title, etc. How do i fix this?, here is my code, its a bit big and messy Don’t mind all of the messy stuff.
MENU scene
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local physics = require “physics”
physics.start()
physics.setGravity(0,0.2)
physics.setDrawMode(“normal”)
local widget = require “widget-v1”
widget.setTheme(“theme_ios”)
–local scaleFactor = 1.0
local physicsData = (require “BalloonTitle”).physicsData(1.0)
–require (“buttoncode”)
local function buttonHit()
storyboard.gotoScene(“Game2”, {effect = “fade”} )
end
local function hitLetter(event)
local obj = event.target
local phase = event.phase
if phase == “began” then
obj:applyLinearImpulse(0,-5,obj.x,obj.y)
end
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local topTitle = display.newGroup()
topTitle.x = 23
local menuBackground = display.newImage(“menuBackground.jpg”)
menuBackground.x = centerX
menuBackground.y = centerY
group:insert(menuBackground)
local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)
local cw, ch = display.contentWidth, display.contentHeight
local wallL = display.newRect( -ox, -oy,2, ch+oy+oy )
physics.addBody(wallL, “static”, { bounce=0.6, friction=1.0 } )
group:insert(wallL)
local wallR = display.newRect( cw-2+ox, -oy, 2, ch+oy+oy )
physics.addBody(wallR, “static”, { bounce=0.6, friction=1.0 } )
group:insert(wallR)
local wallB = display.newRect( -ox, ch-2+oy, cw+ox+ox, 2 )
physics.addBody(wallB, “static”, { bounce=0.6, friction=1.0 } )
group:insert(wallB)
local wallT = display.newRect( -ox, -oy, cw+ox+ox, 2 )
physics.addBody(wallT, “static”, { bounce=0.6, friction=1.0 } )
group:insert(wallT)
local S = display.newImage(topTitle,“S.png”)
physics.addBody(S,“dynamic”,physicsData:get(“S”) )
S:addEventListener(“touch”,hitLetter)
group:insert(S)
local T = display.newImage(topTitle,“T.png”)
T.x = S.x +42
physics.addBody(T,“dynamic”,physicsData:get(“t”) )
T:addEventListener(“touch”,hitLetter)
group:insert(T)
local i = display.newImage(topTitle,“i.png”)
i.x = T.x + 36
physics.addBody(i,“dynamic”,physicsData:get(“i”) )
i:addEventListener(“touch”,hitLetter)
group:insert(i)
local C = display.newImage(topTitle,“C.png”)
C.x = i.x + 42
physics.addBody(C,“dynamic”,physicsData:get(“C”) )
C:addEventListener(“touch”,hitLetter)
group:insert©
local K = display.newImage(topTitle,“K.png”)
K.x = C.x + 42
physics.addBody(K,“dynamic”,physicsData:get(“K”) )
K:addEventListener(“touch”,hitLetter)
group:insert(K)
local Y = display.newImage(topTitle,“Y.png”)
Y.x = K.x + 40
physics.addBody(Y,“dynamic”,physicsData:get(“Y”) )
Y:addEventListener(“touch”,hitLetter)
group:insert(Y)
local bottomTitle = display.newGroup()
bottomTitle.x = 8
local B = display.newImage(bottomTitle,“B.png”)
B.x = S.x - 11
B.y = S.y +59
physics.addBody(B,“dynamic”,physicsData:get(“B”) )
B:addEventListener(“touch”,hitLetter)
group:insert(B)
local A = display.newImage(bottomTitle,“A.png”)
A.x = B.x + 43
A.y = B.y
physics.addBody(A,“dynamic”,physicsData:get(“A”) )
A:addEventListener(“touch”,hitLetter)
group:insert(A)
local L = display.newImage(bottomTitle,“L.png”)
L.x = A.x + 37
L.y = B.y
physics.addBody(L,“dynamic”,physicsData:get(“L”) )
L:addEventListener(“touch”,hitLetter)
group:insert(L)
local L2 = display.newImage(bottomTitle,“L2.png”)
physics.addBody(L2,“dynamic”,physicsData:get(“L2”))
L2.x = L.x + 30
L2.y = B.y
L2:addEventListener(“touch”,hitLetter)
group:insert(L2)
local O = display.newImage(bottomTitle,“O.png”)
O.x = L2.x + 40
O.y = B.y
physics.addBody(O,“dynamic”,physicsData:get(“O”))
O:addEventListener(“touch”,hitLetter)
group:insert(O)
local O2 = display.newImage(bottomTitle,“O2.png”)
O2.x = O.x + 40
O2.y = B.y
physics.addBody(O2,“dynamic”,physicsData:get(“O2”))
O2:addEventListener(“touch”,hitLetter)
group:insert(O2)
local N = display.newImage(bottomTitle,“N.png”)
N.x = O2.x + 37
N.y = B.y
physics.addBody(N,“dynamic”,physicsData:get(“N”))
N:addEventListener(“touch”,hitLetter)
group:insert(N)
local S2 = display.newImage(bottomTitle,“S2.png”)
S2.x = N.x + 37
S2.y = B.y
physics.addBody(S2,“dynamic”,physicsData:get(“S2”))
S2:addEventListener(“touch”,hitLetter)
group:insert(S2)
--makeButton(“Play Game”,centerX,centerY,buttonHit,“Game”,group)
local Play = widget.newButton {style = “blue2Large”,label = “Play”, onRelease = buttonHit}
Play.x = centerX
Play.y = centerY
group:insert(Play)
local Rect1 = display.newRect(20,20,138,50)
physics.addBody(Rect1,“static”)
Rect1.isVisible = false
Rect1.x = Play.x
Rect1.y = Play.y
group:insert(Rect1)
local options = widget.newButton {style = “blue2Large”,label = “Options”, onRelease = buttonHit}
options.x = centerX
options.y = Play.y + 70
group:insert(options)
local Rect2 = display.newRect(20,20,138,50)
physics.addBody(Rect2,“static”)
Rect2.isVisible = false
Rect2.x = options.x
Rect2.y = options.y
group:insert(Rect2)
local credits = widget.newButton {style = “blue2Large”,label = “Credits”, onRelease = buttonHit}
credits.x = centerX
credits.y = options.y + 70
group:insert(credits)
local Rect3 = display.newRect(20,20,138,50)
physics.addBody(Rect3,“static”)
Rect3.isVisible = false
Rect3.x = credits.x
Rect3.y = credits.y
group:insert(Rect3)
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
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
display.remove()
– 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
GAME scene
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() display.setStatusBar(display.HiddenStatusBar) physics.setDrawMode("hybrid") local physics = require "physics" physics.start();physics.setGravity(0,1) local physicsData = (require "Balloon").physicsData(1.0) local foreGround local Balloons local turret local projFiring = false local proj local function newProj(proj) proj = display.newImage(Balloons,"Balloon.png"); proj.x = turret.x ; proj.y = turret.y - 20 physics.addBody( proj, "dynamic",physicsData:get("balloon") ) proj.gravityScale = -3.5 projFiring = false proj.isBullet = true proj.isBodyActive = false proj.isVisible =false end physics.setDrawMode("hybrid") -- local forward references should go here -- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view foreGround = display.newGroup() Balloons = display.newGroup() Balloons.isVisible = true local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY) local cw, ch = display.contentWidth, display.contentHeight local stage = display.getCurrentStage() local background = display.newImage(foreGround,"background.jpg") group:insert(background) local ground = display.newImage(foreGround,"floor.png") physics.addBody(ground,"static") ground.y = 480 group:insert(ground) turret = display.newImageRect(foreGround,"BalloonTurret.png",134,134) turret.x = 160 turret.y = 420 group:insert(turret) newProj(Balloon) 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
cheers, Hazza