Hi guys! This time I have encountered a problem that I do not know how to solve. In my game, each level has a home button which has an animation that enlarges the image. This animation was carried out using the function “object: scale ()” to increase the image and with a short timer to shrink the image, which gives the visual aspect of enlarge and shrink to enter the other scene. Everything works fine, but one of my testers, who is a natural born gamer, found that if you press the home button and the Android back button at the same time, a crash occurs. Here is the home button function:
local function gotoMenu( event ) home:scale( 1.3, 1.3 ) local options = { effect = "crossFade", time = 200 } homeBtnTmr = timer.performWithDelay(300, function() home:scale( .80, .80 ) composer.gotoScene( "levels.menu", options ) end ) return true end
The back button function is configured in main, I assign a variable to the composer in each level but the function is executed from the main lua. It is an old method that I found navigating the forum and the internet and I had not given problems until now. Here is the piece of code that executes the return to the menu from the back button.
local function onKeyEvent( event ) local phase = event.phase local keyName = event.keyName print( event.phase, event.keyName ) if keyName == "back" and phase == "up" then if composer.getSceneName( "current" ) == "levels.menu" then native.requestExit() return true else local lastScene = composer.returnTo print( "previous scene", lastScene ) if lastScene then local options = { effect = "crossFade", time = 200 } composer.gotoScene( lastScene, options ) return true else native.requestExit() end end end return false end
any help to understand and solve why this error “level”#".lua:134: attempt to call method ‘scale’ (a nil value)" comes out I’ll be very greatful!
Thanks in advance
DoDi