problem going from one scene to other

composer is pretty smart, if you are low on memory it will recycle scene not in use. The reasons why you are probably seeing this is composer stores your scene in memory to have fast load times.

See

When my score is less, it gives me texture memory 14mb and when my game overs with a low score, it goes upto 18mb…again when i play again, it come backs to 14 mb … but when my score is higher, and when my game overs with high score, it goes upto 48 mb… and when i click on play again, it lags… gameOver scene doesn’t get removed and game continues playing in the background

it started working now!

Solved !!

Solution?

removed ball:removeEventListener from scene:hide function 

Generally speaking you do not need to remove touch and tap listeners. They are usually on display objects and will be taken off screen when a scene changes and removed when the object is destroyed.

Rob

i have one problem 

when i go to gameOver.lua when my game overs with a score of more than 15000 or somewhat like that, and when i reloads tha game, it works slow. It lags. But when my score is less and then i loose that game, when i reloads it, it works good(doesn’t lag).

So is there any problem?

I have posted my code above :) 

This is my gameOver.lua

local composer = require( "composer" ) local widget = require "widget" local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- background local bg local bgOverlay -- scores local scoreOverlay, scoreText, highScoreText --local transitions local moveBallLeft, moveBallRight -- ball local ball -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local function onButtonTouch( event ) -- body if event.phase == "ended" then local id = event.target.id if id == "main menu" then composer.gotoScene("scene\_play","crossFade") else composer.removeScene("freePlay.freePlay") composer.gotoScene("freePlay.freePlay","crossFade") end end end -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen bg = display.newImageRect(sceneGroup,"freePlay/images/Background image.png",640,1200) bg.x = centerX bg.y = centerY bg.width = screenWidth bg.height = screenHeight bgOverlay = display.newImageRect(sceneGroup, "freePlay/images/gameOver/gameOverBg.png",800,1300) bgOverlay.x = centerX bgOverlay.y = centerY bgOverlay.height = screenHeight scoreOverlay = display.newImageRect(sceneGroup, "freePlay/images/gameOver/scoreOverlay.png",450,140) scoreOverlay.y = screenTop + screenHeight \* 0.2 scoreOverlay.x = centerX scoreText = display.newText(sceneGroup,"",0,0,\_font,80) scoreText.text = "Score:".." "..user.score scoreText.x = scoreOverlay.x scoreText.y = scoreOverlay.y scoreText:setTextColor() btn\_mainMenu = widget.newButton { width = 330 , height = 126, defaultFile = "freePlay/images/gameOver/btn\_mainMenu.png", overFile = "freePlay/images/gameOver/btn\_mainMenu\_over.png", id = "main menu", onEvent = onButtonTouch, label = "Main Menu", fontSize = 50, font = \_font, labelColor = { default = {1,1,1}, over = {1,0.9,1}} } btn\_mainMenu.x = screenLeft + btn\_mainMenu.width \* 0.65 btn\_mainMenu.y = centerY + btn\_mainMenu.height sceneGroup:insert(btn\_mainMenu) btn\_playAgain = widget.newButton { width = 330 , height = 126, defaultFile = "freePlay/images/gameOver/btn\_mainMenu.png", overFile = "freePlay/images/gameOver/btn\_mainMenu\_over.png", id = "play again", onEvent = onButtonTouch, label = "Play Again", fontSize = 50, font = \_font, labelColor = { default = {1,1,1}, over = {1,0.9,1}} } btn\_playAgain.x = btn\_mainMenu.x + btn\_mainMenu.width \* 1.1 btn\_playAgain.y = centerY + btn\_mainMenu.height sceneGroup:insert(btn\_playAgain) if user.score \> 100000000 then scoreText.size = 60 end highScoreText = display.newText(sceneGroup , "High Score:".." "..user.highscore,0,0,\_font,50) highScoreText.x = scoreOverlay.x highScoreText.y = scoreOverlay.y + scoreOverlay.height \* 0.8 highScoreText:setTextColor() if user.score \> user.highscore then print("High score changed ") user.highscore = user.score loadsave.saveTable(user,"user.json") highScoreText.text = "High Score:".." "..user.score highScoreText.x = scoreOverlay.x else print("High Score not changed ") highScoreText.text = "High Score:".." "..user.highscore end if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",60,60) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",60,60) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",60,60) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",60,60) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",60,60) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",60,60) end ball.x = scoreOverlay.x + scoreOverlay.width \* 0.5 ball.anchorX = 1 ball.anchorY = 1 ball.y = scoreOverlay.y - scoreOverlay.height \* 0.5 end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen function moveBallLeft() transition.to(ball,{x = scoreOverlay.x + scoreOverlay.width \* 0.5 ,time = 2000,anchorX = 1,onComplete = moveBallRight}) end function moveBallRight() transition.to(ball,{x = scoreOverlay.x - scoreOverlay.width \* 0.5 ,time = 2000,anchorX = 0,onComplete = moveBallLeft }) end moveBallRight() end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen user.score = 0 loadsave.saveTable(user,"user.json") print("Score set to zero") end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

Are you doing anything different before you go to the gameOver scene? Like turning off listeners, timers, transitions for one but not the other?

Rob

I removed the timers and event listeners ( you can see the code above)
I think it is because of global functions
I have two global functions in gameOver and one in game…it might be the case of memory leak :confused:
Confused.
Btw i have too many queries too be answered by you all…should i ask them in this topic too aur should i post a new tppic?? Firstly we’ll clear this topic​:slight_smile::slight_smile:

That’s not the question I was really asking. I don’t thing gameOver.lua is causing your slow down. It sounds like when you go back to the game scene, you may be doubling up a timer in “freePlay” module or doubling up an enterFrame listener that could be killing your performance. It could be the globals, but unless you’re using the same function names. You are also not stopping your move ball transition. In this scene.

If you feel you’re leaking memory you should probably put some prints in your code that prints your memory value.

As for other topics, please ask in new threads.

Thanks

Rob

How can i print memory values ??

print( "Texture Memory", string.format("%0.2fMB", system.getInfo( "textureMemoryUsed" ) / (1024 \* 1024) ) ) print( "Lua Memory", string.format( "%0.2fMB", collectgarbage("count") / 1024 ) )

You can see my sendEnemies function in game scene…there is math.random usage…so it possible to spawn enemies where my player is there??
Like my ball is my player…it is draggable…so if user drags the ball to the right side of the screen, so enemies should be spawning half the time from right and vice versa.

anybody??

what is lua memory and texture memory

im getting 9.55 mb texture memory and 0.44 lua memory…is it okay ??

https://forums.coronalabs.com/topic/16134-max-texture-memory/

Lua memory is memory allocated from the devices main pool of memory. It is where strings, numbers, and tables get their memory.

Texture memory is memory used by the Graphics Processing Unit (GPU) to manage the images being pipelined to the screen. Depending on the device, the GPU may borrow main memory to supplement its own. In Corona Terms, this is memory used by display.newImage() and display.newImageRect() and similar.

Images take up as much memory as multiplying their dimensions by 4. Thus a 64 x 128 pixel image is 32,768 bytes of texture memory or 32Kbytes (Kilobytes = 1024 bytes) or 0.032MBytes (Mega bytes = 1024 Kilo bytes = 1 million plus bytes.)  A 2048x2048 sprite sheet takes up 16 megabytes of memory.

Most devices have at least 256 megabytes of memory. Most modern devices are 512 megabytes up to 2 gigabytes (2048 megabytes). Now of course your app doesn’t get all of that memory. The operating system uses a good chunk. There’s no good way to measure, but keeping your app between 50 megabytes and 200 megabytes.  So 9 isn’t much at all. And for the Lua memory 0.44 is pretty low. Though unless you have some really big data structures with lots of data, the Lua memory shouldn’t get very high at all.

Rob

My game still lags when score is bigger
Sometimes, after losing, when going to gameOver scene and hitting play again button, the gameOver scene doesnt get removed…the gameOver scene doesnt get removed but the game works in background…
Should i use composer overlay instead??

Using an overlay won’t change anything. What ever is causing your slow down will continue to do so.

You need to find out what’s causing the slow down.  Does your memory increase over time?

Look at the code where you determine if the score is above a certain value. Make sure to kill your transitions running in your gameOver scene. Use composer.removeScene() to remove the gameOver scene (remember you can’t remove a scene if you’re in it, so wait until you’re back to your game scene to remove gameOver.