When Image loads gotoScene

I have had an idea to a problem I have been having. But I need a piece of code that when an image called “alertbg.png” appears on the screen it takes you to another scene called “gameover.lua”. I have not been able to find anything to help me so far. I would love someones help. I am using storyboard and I am also using physics. [import]uid: 111430 topic_id: 23192 reply_id: 323192[/import]

First of all you don’t want to do this. Why load the image to just change scenes and not show the image again.

Now if loading the image you are going to make it a touch event for the user to trigger the scene change (and dismiss the alert graphic) or have it show for X number of seconds then do the scene change, then that’s more practical.

Which way would you like it?

Rob
[import]uid: 19626 topic_id: 23192 reply_id: 92799[/import]

I would like the user to touch the image and then for it to take the user to the other scene. What would the code be to do this? not sure on this as I am a newbie [import]uid: 111430 topic_id: 23192 reply_id: 92807[/import]

Okay this one is pretty easy.

local alertbox = display.newImage("alertbg.png")  
  
local function gameOver(event)  
 -- do your end game call here:  
 storyboard.gotoScene("gameover")  
end  
  
alertbox:addEventListener("tap",gameOver)  
  

Of course you will need to position your graphic, add it to your group, etc.
[import]uid: 19626 topic_id: 23192 reply_id: 92819[/import]

thanks I will try this out in a bit. I hope it works with my game. [import]uid: 111430 topic_id: 23192 reply_id: 92820[/import]

Right I have tried the code you posted and i have tried it in all sorts of places but it won’t work. How would I include it in the code below. the last piece the function showAlert()is where the image appears when the game ends. I need it so that when the image appears that you tap the image and it goes to the “gameover” scene.

Would really like some help.

Thanks

This is the entire code that i have that tells you when it is the end of the game and displays the image.

[code]

– Check for Game Over

if(lives < 0) then
showAlert()
end

– Levels

if(score > 500 and score < 502) then
moveSpeed = 3
end
end

function collisionHandler(e)
– Grab Lives

if(e.other.name == ‘live’) then
display.remove(e.other)
e.other = nil
lives = lives + 1
livesTF.text = ‘x’ … lives
end

– Bad Blocks

if(e.other.name == ‘bad’) then
lives = lives - 1
livesTF.text = ‘x’ … lives
end
end

function showAlert()
gameListeners(‘rmv’)
local alert = display.newImage(‘alertBg.png’, 70, 190)

transition.from(alert, {time = 200, xScale = 0.8})
end

[/code] [import]uid: 111430 topic_id: 23192 reply_id: 92837[/import]

I hope thats not all the code. Line 12 ends something I can’t see. I also don’t know if you’ve declared “showAlert” at the top, if not the call to it on line 4 wont work.
The code I provided earlier would fit in right after your line 34 above changing my code from “alertbox” to “alert” and of course not duplicating the display.newImage call.

[import]uid: 19626 topic_id: 23192 reply_id: 92842[/import]

There is alot more code. I have declared “showAlert” in my code at the top and i have added your code to the loaction you suggested and i think i am close to getting it working. but i get the following error in command prompt:

[c]: in function @dispatchEvent
?: in function ‘gotoScene’
…\corona projects\crate fall v3\level1.lua:330: in function

Here is the code with your code added.

local function gameOver(event)  
 -- do your end game call here:  
 storyboard.gotoScene("screen2")  
end  
   
alert:addEventListener("tap",gameOver)  
  
  
 transition.from(alert, {time = 200, xScale = 0.8})  
 end  

The line of code that it says the error is on is

 storyboard.gotoScene("screen2")  

I have a temp file called “screen2” just to test this as “gameover” is in a different folder with a different project.

Ryan [import]uid: 111430 topic_id: 23192 reply_id: 92845[/import]

I have got it working. I had not had the stuff you needed for the storyboard api.

I got it working now. just to get everything else done now.

Thank you so much! [import]uid: 111430 topic_id: 23192 reply_id: 92847[/import]