Button Activated Scene Transitions

How can i make a button make a scene transition? I want to press a photo i made and it moves to a new screen were my game starts. BTW im 13

Here’s the documentation on Corona’s event model.

http://docs.coronalabs.com/guide/events/detectEvents/index.html

To achieve what you’re describing, you would just create your event function to transition the scene, and make a listener for the photo object. Checking out the storyboard documentation might be useful as well, so that you can see how the scenes are transitioned by default, and how you can modify them.

http://docs.coronalabs.com/api/library/storyboard/

im very new to all this coding. which version of storyboard am i supposed too use. this is my code so far

---------------------------------------------- Photo 

                                                

local backround = display.newImage(“Blue.png”)

local backround = display.newImage(“Pile.png”)

local ground = display.newImage(“Play.png”)

ground.x = 160; ground.y = 400

---------------------------------------------- Status Bar

                                              

display.setStatusBar( display.HiddenStatusBar )

I want to turn my Play.png into my button that starts the game

Hi Luke and welcome to Corona SDK.  We think it’s awesome that young programmers like yourself are getting involved. 

As for your question, it’s really too much for a forum post.  Trying to explain story board and touch listeners has been written up in various guides, tutorials, and such.  I would recommend you read through our Corona University pages to get up to speed on Storyboard and Touch event listeners.  Start here:

http://www.coronalabs.com/resources/tutorials/getting-started-with-corona/

and you are interested in the “Events and Listeners” area (http://www.coronalabs.com/resources/tutorials/events-and-listeners/) and the User Interface, Scenes and Widgets area as well (http://www.coronalabs.com/resources/tutorials/user-interface-scenes-and-widgets/)

Again welcome aboard!

Rob

Yea im trying to make a game and i was making a main menu and i started by making a title using gimp so thats a photo and i made another that said play in it and i wanted to make it so when i press it, it starts the game. i havent coded the game yet. and i dont care if i only have to touch the screen any where i just want to make the main menu and then start making the actual game part.

Is this code i could use for opening a scene with  button:

– 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.jpg”, 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} },

        defaultFile=“button.png”,

        overFile=“button-over.png”,

        width=154, height=40,

        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

Yes, that’s part of a storyboard scene.  There are some additional bits at the top and bottom that you don’t have listed there.  Also, main.lua isn’t a storyboard scene, its for things non-storyboard  like system event handlers and such.  You would just include the storyboard module in main.lua and then go to your scene. 

Ok I found a solution i just modified the demo game to my liking with a new background and title but its very small will fix later. And now i have another question how can i make a object go from point a to b to a tob on and on until i tap the screen depending where it is you continue but if you dont get the correct spot game over. do understand what i mean?

Here’s the documentation on Corona’s event model.

http://docs.coronalabs.com/guide/events/detectEvents/index.html

To achieve what you’re describing, you would just create your event function to transition the scene, and make a listener for the photo object. Checking out the storyboard documentation might be useful as well, so that you can see how the scenes are transitioned by default, and how you can modify them.

http://docs.coronalabs.com/api/library/storyboard/

im very new to all this coding. which version of storyboard am i supposed too use. this is my code so far

---------------------------------------------- Photo 

                                                

local backround = display.newImage(“Blue.png”)

local backround = display.newImage(“Pile.png”)

local ground = display.newImage(“Play.png”)

ground.x = 160; ground.y = 400

---------------------------------------------- Status Bar

                                              

display.setStatusBar( display.HiddenStatusBar )

I want to turn my Play.png into my button that starts the game

Hi Luke and welcome to Corona SDK.  We think it’s awesome that young programmers like yourself are getting involved. 

As for your question, it’s really too much for a forum post.  Trying to explain story board and touch listeners has been written up in various guides, tutorials, and such.  I would recommend you read through our Corona University pages to get up to speed on Storyboard and Touch event listeners.  Start here:

http://www.coronalabs.com/resources/tutorials/getting-started-with-corona/

and you are interested in the “Events and Listeners” area (http://www.coronalabs.com/resources/tutorials/events-and-listeners/) and the User Interface, Scenes and Widgets area as well (http://www.coronalabs.com/resources/tutorials/user-interface-scenes-and-widgets/)

Again welcome aboard!

Rob

Yea im trying to make a game and i was making a main menu and i started by making a title using gimp so thats a photo and i made another that said play in it and i wanted to make it so when i press it, it starts the game. i havent coded the game yet. and i dont care if i only have to touch the screen any where i just want to make the main menu and then start making the actual game part.

Is this code i could use for opening a scene with  button:

– 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.jpg”, 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} },

        defaultFile=“button.png”,

        overFile=“button-over.png”,

        width=154, height=40,

        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

Yes, that’s part of a storyboard scene.  There are some additional bits at the top and bottom that you don’t have listed there.  Also, main.lua isn’t a storyboard scene, its for things non-storyboard  like system event handlers and such.  You would just include the storyboard module in main.lua and then go to your scene. 

Ok I found a solution i just modified the demo game to my liking with a new background and title but its very small will fix later. And now i have another question how can i make a object go from point a to b to a tob on and on until i tap the screen depending where it is you continue but if you dont get the correct spot game over. do understand what i mean?