Clean data form scene - lua

How can i clear all objects out of 'game.lua, when i leave the game scene all the data is still on the screen, how can i remove everything when i leave and reset it back to the start position when i go back to 'game.lua' ?
game.lua:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
_W = display.contentWidth
_H = display.contentHeight
system.setIdleTimer(false); -- Prevent the app from becoming suspended
local physics = require "physics"
physics.start()
clouts = true
score = 0
speeda1 = 100
speedb1 = 150
function scene:createScene( event )
local group = self.view
end
function scene:enterScene( event )
local group = self.view
--start drop zone
if clouts then
local badclout1 = {}
local bad1Group = display.newGroup()
local function spawnBC1()
local badclouts1 = display.newImage("BCloud1.png")
badclouts1.x = math.random(0, _W)
physics.addBody( badclouts1, "dynamic", { density=.1, bounce=.1, friction=.2, radius=45 } )
badclouts1.name = "BCloud1"
badclouts1.bodyType = "kinematic"
badclouts1.isSensor = true
badclouts1.y = math.random(-100, -50)
badclouts1.index = #badclout1 + 1
bad1Group:insert(badclouts1)
badclouts1.rotation = math.random(-10,10) -- Rotate the object
badclouts1:setLinearVelocity(0, math.random(speeda1, speedb1)) -- Drop down
badclout1[badclouts1.index] = badclouts1
tmrSpawn1 = timer.performWithDelay(math.random(spawna, spawnb), spawnBC1)
return badclouts1
end
tmrSpawn1 = timer.performWithDelay(math.random(1000, 10000), spawnBC1)
local function removeBomb()
for i, v in pairs(badclout1) do
if badclout1[i].y >1000 then
badclout1[i]:removeSelf()
badclout1[i] = nil
end
end
end
Runtime:addEventListener("enterFrame", removeBomb)
end
-- end drop zone
local function speatTimer()
speeda1 = speeda1+1
speedb1 = speedb1+1
end
local mainTimer = timer.performWithDelay( 550, speatTimer, 200 )
function gameOver()
storyboard.gotoScene("restart", "fade", 400)
end
end
function scene:exitScene( event )
local group = self.view
Runtime:removeEventListener( "collision", onCollision )
Runtime:removeEventListener("accelerometer", onTilt)
Runtime:removeEventListener("enterFrame", removeBomb)
end
function scene:destroyScene( event )
local group = self.view
end
function scene:overlayEnded( event )
local group = self.view
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
scene:addEventListener( "overlayEnded", scene )
return scene
Regards Kevin,

if you are using storyboard and want to reset all the values you can remove the scene before you go to another scene so when you go again to the same scene all will be created
function scene:exitScene( event )
local group = self.view
Runtime:removeEventListener( "collision", onCollision )
Runtime:removeEventListener("accelerometer", onTilt)
Runtime:removeEventListener("enterFrame", removeBomb)
storyboard.removeScene("SCENE TO REMOVE")
end
or do this after you go to the scene
function scene:enterScene( event )
storyboard.removeScene("SCENE TO REMOVE")
end
here's the link on how to implement it.
http://www.coronalabs.com/blog/2012/07/31/storyboard-scene-purging-vs-removal/

There are two way to reset back your object positions and variable data
The first one is to create a function like this
function resetGame()
--your initial position and data values here
end
And call it whenever you need to reset your game but you will manually code the reset values.
The second one is by creating a dummy scene. A dummy scene is a scene that will redirect you again to the game scene like this
Dummy Scene
function scene:createScene( event )
local group = self.view
storyboard.gotoScene( "scenes.Game" ) --scene/Game.lua
end
to reset the values of your objects and variables, but don't forget to remove all of the listeners and put it on the exitScene() function when you go to the dummy scene.

Since you are using storyboard, why not simply insert all your display objects into group:
group:insert(someobject)
and let the scene manager do the work for you. By not creating the scene in scene:createScene() your ability to transition the screen won't work. By not putting things into the group, it can't remove them for you when the scene goes away.

Related

corona composer background next scene not showing

I have a lot of difficulties with composer...it's not so easy!
My previous scene is "game" (game.lua) everything is ok
When i go to my scene "recolt" with this snippet inside my game lua :
local function goTo()
print("gotoscene")
composer.gotoScene( "recolt", { time = 1000, effect = "fromRight", params = params } )
end
timer.performWithDelay( 1000, goTo )
:The problem is that i see my previous scene behind my recolt scene and i can't see my background but i see my circle who's moving ??? however my sceneGroup is correct :
sceneGroup:insert(background,circle)
When i do :
sceneGroup:insert(circle,background)
I see my background who hide my previous scene and my circle. > behavior expected
What's wrong? i would like to see my background and my circle in y "recolt" scene. Could you help me ? Thanks a lot...Below the snippet "recolt.lua".
--recolt.lua
local composer = require( "composer" )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
params = event.params
local background=display.newImageRect("back02.png",display.contentWidth*.5,d isplay.contentHeight*.5,320,480)
background.x,background.y=display.contentWidth*.5,display.contentHeight*.5
background.xScale,background.yScale=2,2
background.alpha=1
local circle = display.newCircle(120,100,100)
sceneGroup:insert(background,circle)
timeT=150
local function tr4()
transition.to(circle,{time=timeT,x=200,y=300,alpha=1,transition=easing.linear, xScale=1,yScale=1})
end
local function tr3()
transition.to(circle,{time=200,x=100,y=300,transition=easing.linear, xScale=.2 ,yScale=.5,onComplete=tr4})
end
local function tr2()
transition.to(circle,{time=200,x=200,y=295,transition=easing.linear, xScale=.2 ,yScale=.2,alpha=.2,onComplete=tr3})
end
local function tr1()
transition.to(circle,{time=timeT,x=300,y=300,transition=easing.linear, xScale= .5,yScale=.5,onComplete=tr2})
end
timer.performWithDelay(700,tr1,-1)
end
function scene:show( event )
local sceneGroup = self.view
params = event.params
if event.phase == "did" then
--physics.start()
end
end
function scene:hide( event )
local sceneGroup = self.view
if event.phase == "will" then
--
-- Remove enterFrame listeners here
--
--physics.stop()
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene
You need to check the docs: object:insert()
The problem is you can only add 1 object into the scene with insert() function, so you only need to change
sceneGroup:insert(background,circle)
to
sceneGroup:insert(background)
sceneGroup:insert(circle)
The order matters, the first object you create go back in the scene.

Can't see text in Storyboard

I am fairly new to Corona SDK and was trying to make a game menu, but when I run the code it just don't display the text.I have know for sure that the program make it's way up to this file. Any idea why?
local storyboard = require ("storyboard")
local scene = storyboard.newScene()
display.setStatusBar (display.HiddenStatusBar)
local function ButtonTap (event)
storyboard.gotoScene(event.target.goto, {effect="slideDown"})
return true
end
function scene:CreateScene (event)
local group = self.view
-->Play Button
local PlayBtn = display.newText ("Play",0,0)
PlayBtn.x = display.contentHeight/2
PlayBtn.y = display.contentWidth/2
PlayBtn.goto = "Play"
PlayBtn:addEventListener("tap", ButtonTap)
group:insert(PlayBtn)
-->Exit Button
local ExitBtn = display.newText ("Play",0,0)
ExitBtn.x = display.contentHeight/2
ExitBtn.y = display.contentWidth/2 + 60
ExitBtn.goto = "Play"
ExitBtn:addEventListener("tap", ButtonTap)
group:insert(ExitBtn)
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
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 view)
function scene:destroyScene( event )
local group = self.view
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
Thanks in advance :)
function scene:CreateScene( event ) should be function scene:createScene( event ) if you follow the standard naming conventions. Lua is case sensitive. In:
scene:addEventListener( "createScene", scene )
You're using a lowercase "c", but in the function, you use an uppercase "C". These have to match and the Corona standard would be to go with the lowercase version.

Corona SDK onRowTouch gotoScene

I cannot change the scene with composer or storyboard. I am trying to change the scene when you touch a row in tableview. I am able to change the scene from the main file to the file with the tableview. The tableview touch is not working though.
Some of my code is below:
local widget = require( "widget" )
local storyboard = require( "storyboard" )
local composer = require( "composer" )
local scene = composer.newScene()
function RowTouch( event )
composer.gotoScene( "thehike" )
end
myTable = widget.newTableView
{
width = display.contentWidth,
height = display.contentHeight,
backgroundColor = { .47, .66, .53 },
topPadding = 0,
hideBackground = false,
onRowRender = onRowRender,
onRowTouch = RowTouch,
noLines = true,
}
for i=1, #hike do
myTable:insertRow{
rowHeight = 220,
isCategory = false,
lineColor = { .47, .66, .53 }
}
end
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-----------------------------------------------------------------------------------------
return scene
Your code does not work for a couple of reasons. You have a dangling end in line 34 and you did not define hike. You probably need a smaller rowHeight in order to show the rows in your view:
local myTable = widget.newTableView
{
left = 0,
top = 0,
height = 330,
width = 300
}
myTable:insertRow(
{
isCategory = false,
rowHeight = 40,
rowColor = rowColor,
lineColor = {.47, .66, .53}
}
)
Also, the documentation is pretty good on this[1].
[1] http://docs.coronalabs.com/api/library/widget/newTableView.html

attempt to index global 'group' (a nil value) - lua

I am new to lua and corona sdk, and i am using the storyboard api to create an app. i have a main.lua which just sends the user to menu.lua. menu.lua code looks like this:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "widget" library
local widget = require "widget"
-- forward declarations and other locals
local playBtn
-- 'onRelease' event listener for playBtn
local function onPlayBtnRelease()
-- go to level1.lua scene
storyboard.gotoScene( "level1", "fade", 500 )
return true -- indicates successful touch
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- display a background image
local background = display.newImageRect( "background.png", display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
-- create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( "logo.png", 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 100
-- create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label="Play Now",
labelColor = { default={255}, over={128} },
fontSize = "40",
defaultFile="button.png",
overFile="button-over.png",
width=250, height=80,
onRelease = onPlayBtnRelease -- event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 125
-- all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
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 listenets, unload sounds, etc.)
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
if playBtn then
playBtn:removeSelf() -- widgets must be manually removed
playBtn = nil
end
end
-- "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 whenever 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
and this is my level1.lua:
-----------------------------------------------------------------------------------------
--
-- level1.lua
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "physics" library
local physics = require "physics"
physics.start(); physics.pause()
--------------------------------------------
-- forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- create a grass object
local bar= display.newImage( "bar.png", 0, 398)
local function update( event )
local group = self.view
updateBackgrounds()
end
local background1 = display.newImage("images/bg.png")
background1.x = 240
background1.y = 160
local background2 = display.newImage("images/bg.png")
background2.x = 760
background2.y = 160
function updateBackgrounds()
local group = self.view
--near background movement
background1.y = background1.y - (3)
--if the sprite has moved off the screen move it back to the
--other side so it will move back on
if(background1.x < -239) then
background1.x = 760
end
background2.y = background2.y - (3)
if(background2.x < -239) then
background2.x = 760
end
end
--this is how we call the update function, make sure that this line comes after the
--actual function or it will not be able to find it
--timer.performWithDelay(how often it will run in milliseconds, function to call,
--how many times to call(-1 means forever))
timer.performWithDelay(1, update, -1)
end
-- all display objects must be inserted into group
group:insert( background1 )
group:insert( background2 )
group:insert( bar )
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
physics.start()
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
physics.stop()
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
package.loaded[physics] = nil
physics = nil
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 whenever 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
And here is my error:
When you create the group variable in the updateBackgrounds() method, self.view is nil because self.view only exists in the methods createScene() and enterScene(). What I recommend to do is create a global variable on the beginning of the script called group and then on your createScene method just do group = self.view without the "local" identifier.
Something like this:
--begining of the script
local group
-- Called when the scene's view does not exist:
function scene:createScene( event )
group = self.view
end
this creates a variable called group that has the reference of the self.view variable through all the script.
Another good option is to create a new global group and add it to the self.view on the createScene() method, this keeps things clean.
local globalGroup
function scene:createScene(event)
local group = self.view
globalGroup = display.newGroup()
group:insert(globalGroup)
end
Hope this helps.
This might because functions are not ending properly. Check if you are ending each function in level1.lua.
You are calling a function with a timer, but that function doesn't have access to self.view. Use the "enterFrame" event on Runtime, this is called at every frame:
function scene:enterFrame(event)
local group = self.view
... stuff from update functions ...
end
Runtime.addEventListener("enterFrame", scene)
If you don't need every frame, but say every second frame, put a counter in scene:enterFrame. Or in scene:enterFrame compute how much time since last call to determine if update needed.
local group
Should become
group
so that it is indeed global. Adding the local makes the 'global' become a part of only the body, not the functions, vice versa. If you need Lua practice, Roblox is a good place to start. The provide libraries already in your scripts so that it is easier to code. Try it. ;)

A table does not get deleted on scene change, CoronaSDK Storyboard

Basically, I have a table that has images that move horizontally, when I change scenes it stays there, even though I didn't call for it.. As in, on there is no code for it in offlinemode.lua.. I'm thinking that for some reason it's a global element..
Here is main.lua:
local storyboard = require "storyboard"
local options =
{
effect = "slideLeft",
time = 800
}
storyboard.gotoScene( ".Lua.MainMenu", options )
This MainMenu.lua
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
--/////// Unamed game (so far) main.lua is GUI/MENU
-- //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////
--implements the storybord then deletes it upon completeion--
local storyboard = require "storyboard"
storyboard.purgeOnSceneChange = true
--You may began now-- (incorrectly speeleed corrctly)
local scene = storyboard.newScene()
--makes a container for the background--
-- createScene event simply creates a background image
function scene:createScene( event )
local bg = display.newImage( self.view, "background.png" )
end
scene:addEventListener( "createScene" )
--end of aking a container for the background--
--disables the status bar--
display.setStatusBar( display.HiddenStatusBar )
--end of disabling of status bar--
--Returns Screen Width and Screen Height--
_W = display.contentWidth;
_H = display.contentHeight;
--end of returning screen width and height--
--////////////////////////////////////////////////end of the background\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--**********************************************************************************************************************--
--////////////////////////////////////////////////Menu Buttons\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--Set up a local container for the buttons--
local widget = require( "widget" )
local PlayBtn
local function onPlayBtnRelease()
-- go to level1.lua scene
storyboard.gotoScene( ".Lua.offlinemode", "slideLeft", 500 )
display.remove(initstar)
return true -- indicates successful touch
end
local PlayBtn = widget.newButton
{
left = 160,
top = 80,
label = "Offline",
labelAlign = "center",
font = "Arial",
fontSize = 18,
labelColor = { default = {0,0,0}, over = {255,255,255} },
onRelease = onPlayBtnRelease
}
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
--********************************************************************************************************************--
--///////////////////////////////////////Setting up background\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--
--set up the table to store the clouds in--
local starTable = {}
--end of the table to store the clouds in--
--creates three containers with a picture of a cloud--
function initStar()
local star1 = {}
star1.imgpath = "/images/Cloud1.png"; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star
table.insert(starTable, star1); --Insert Star into starTable
local star2 = {}
star2.imgpath = "/images/cloud2.png";
star2.movementSpeed = 12000;
table.insert(starTable, star2);
local star3 = {}
star3.imgpath = "/images/cloud3.png";
star3.movementSpeed = 14000;
table.insert(starTable, star3);
end
--ends the function--
--Gets random stars from the table, positioning them randomly--
function getRandomStar()
local temp = starTable[math.random(1, #starTable)] -- Get a random star from starTable
local randomStar = display.newImage(temp.imgpath) -- Set image path for object
randomStar.myName = "star" -- Set the name of the object to star
randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move
randomStar.y = math.random(10,_H) -- Set starting point of star at a random X position
randomStar.x = -40; -- Start the star off screenm
starMove = transition.to(randomStar, { --Move the Clouds
time=randomStar.movementSpeed, --sets the speed relative to it's lifetime
onComplete = function(self) self.parent:remove(self); self = nil; end, -- removes itself
x=500 --speed of ?
}) -- Move the Clouds
end
--The end of this function--
--Starts the timer before the Clouds "spawn"--
function startGame()
starTimer1 = timer.performWithDelay(1070,getRandomStar, 0)
starTimer2 = timer.performWithDelay(2030,getRandomStar, 0)
starTimer3 = timer.performWithDelay(2070,getRandomStar, 0)
end
--ends the function--
initStar()
startGame()
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever 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().
function scene:didExitScene( event )
storyboard.purgeScene( "scene1" )
end
scene:addEventListener( "didExitScene" )
return scene
--end the Online function--
and finally offlinemode.lua:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local background = display.newImage("background.png")
local image = display.newImage("/images/ButtonStartOffline.png")
function scene:createScene( event )
end
function scene:enterScene( event )
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
If it works, tell me why it didn't for me please..
you should put the image to the display group either in createScene or enterScene so when you go to another scene it will remove all the image within that scene here's the implementation of the it see the code
function scene:createScene( event )
local group = self.view
--/////////////////////Setting up background\\\\\\\\\\\\\\\\\\--
--set up the table to store the clouds in--
local starTable = {}
--end of the table to store the clouds in--
--creates three containers with a picture of a cloud--
function initStar()
local star1 = {}
star1.imgpath = "/images/Cloud1.png"; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star
table.insert(starTable, star1); --Insert Star into starTable
local star2 = {}
star2.imgpath = "/images/cloud2.png";
star2.movementSpeed = 12000;
table.insert(starTable, star2);
local star3 = {}
star3.imgpath = "/images/cloud3.png";
star3.movementSpeed = 14000;
table.insert(starTable, star3);
end
--ends the function--
--Gets random stars from the table, positioning them randomly--
function getRandomStar()
local temp = starTable[math.random(1, #starTable)] -- Get a random star from starTable
local randomStar = display.newImage(temp.imgpath) -- Set image path for object
randomStar.myName = "star" -- Set the name of the object to star
randomStar.movementSpeed = temp.movementSpeed; -- Set how fast the object will move
randomStar.y = math.random(10,_H) -- Set starting point of star at a random X position
randomStar.x = -40; -- Start the star off screenm
group:insert(randomStart) **-- inserting random star into Group**
starMove = transition.to(randomStar, { --Move the Clouds
time=randomStar.movementSpeed, --sets the speed relative to it's lifetime
onComplete = function(self) self.parent:remove(self); self = nil; end, -- removes itself
x=500 --speed of ?
}) -- Move the Clouds
end
--The end of this function--
--Starts the timer before the Clouds "spawn"--
function startGame()
starTimer1 = timer.performWithDelay(1070,getRandomStar, 0)
starTimer2 = timer.performWithDelay(2030,getRandomStar, 0)
starTimer3 = timer.performWithDelay(2070,getRandomStar, 0)
end
--ends the function--
initStar()
startGame()
end
Can you try to add " randomStar.y = -100" to your new scene this will not remove them but will take them out of view.
scene:addEventListener( "didExitScene")
Should be :
scene:addEventListener( "didExitScene", scene )
In your last part of the first code snippet

Resources