Credits Screen

Note: I have posted a topic similar to this about 6 days ago but I couldn’t find the thread after an hour of searching. I found the thread using Google but it would just take me to the main page of the forums.

 

My problem is that I have a title screen which has a play button and a credits button. When I click on the credits button, new objects are displayed while the title screen objects are set to invisible using the [lua]titleView.isVisible = false[/lua] function. However, I cannot figure out how to go back to the title view from that credits view. I wanted it so that whenever the background of the credits view screen was clicked, it would go back to the title view. Here is my code:

 

[lua]

 

–> Add physics engine, start up the engine, and apply engine

local physics = require(“physics”)

physics.start()

 

–>Set gravity to act “down” (ie, toward bottom of the device)

physics.setGravity(0, 2.5)

 

–>Displays Background

local background = display.newImage (“Title Screen.png”)

 

–>Requires Storyboard API

local storyboard = require “storyboard”

 

–>Displays Play Game Button

local playgame = display.newImage (“playBtnBigger.png”)

playgame.x = display.contentWidth/2

playgame.y = display.contentHeight - 160

 

–>Displays Credits Button

local credits = display.newImage (“creditsBtnBigger.png”)

credits.x = display.contentWidth/2

credits.y = playgame.y + 60

 

–>Group into Title View

local titleView = display.newGroup(background, playgame, credits)

 

–>Add Tap Event for Play Game

function startGame(event)

    local playgame = event.target

    storyboard.gotoScene(“game”, “fade”, 400)

end

 

–> Add Tap Event for Credits

function showCredits(event)

    titleView.isVisible = false

    

    local creditsBG = display.newImage (“creditsScreen.png”)

    

    local creditsBalloonDar = display.newImage (“creditsBalloonDar.png”)

    physics.addBody (creditsBalloonDar, “static”, {bounce = 1.5, friction = 10, radius = 45})

    creditsBalloonDar.x = display.contentWidth/2 - 95

    creditsBalloonDar.y = display.contentHeight/2

    

    local creditsBalloonJay = display.newImage (“creditsBalloonJay.png”)

    physics.addBody (creditsBalloonJay, “static”, {bounce = 1.5, friction = 10, radius = 45})

    creditsBalloonJay.x = creditsBalloonDar.x + 170

    creditsBalloonJay.y = creditsBalloonDar.y + 150

    

    local creditsBalloonCebo = display.newImage (“creditsBalloonCebo.png”)

    physics.addBody (creditsBalloonCebo, “static”, {bounce = 1.5, friction = 10, radius = 45})

    creditsBalloonCebo.x = creditsBalloonDar.x - 150

    creditsBalloonCebo.y = creditsBalloonDar.y + 150

    

        function moveCreditBalloonsDar()

            transition.to(creditsBalloonDar, {time=750, speed=0.5, y=math.random(300, 370), onComplete=moveCreditBalloonsDar})

            transition.to(creditsBalloonJay, {time=750, speed=0.5, y=math.random(220, 300)})

            transition.to(creditsBalloonCebo, {time=750, speed=0.5, y=math.random(220, 300)})

        end

        

        moveCreditBalloonsDar()

end

 

–> Add Event Listeners for Play Game & Credits

playgame:addEventListener(“tap”, startGame)

credits:addEventListener(“tap”, showCredits) [/lua]

 

Any help would be appreciated.

Bump.

Edit: delete

Couple of things…  We used to support a 3rd party service that used “credits” ad the name of API.  I think the way you’re using the variable “credits” is probably safe, but just to be sure, you might want to rename it to gameCredits or something.

 

I don’t see any buttons in your credit view to hide the credit view and show your other stuff.  How does it know to go away and show the other bits again.

 

I tried to make another touch function for the background that is showing in the creditsView so that whenever the user touches the background, it returns to the titleView. Inside the touch function, I tried storyboard.gotoScene(“start”) but that didn’t work and neither did me just making the objects in creditsView invisible and the titleView Visible.So I was wondering, what kind of code would I put in that would do that?

 

And thanks for the tip. Will change to gameCredits.

Your code above doesn’t show any hints that you are using Storyboard to manage scenes, so storyboard.gotoScene() won’t work unless you are using separate modules with all the required parts needed to make it a storyboard module. 

If you’re not using storyboard I would go back and try adding that touch/tap handler to the background of the credits screen, and then post your code back for us to take a look.

I am using storyboard in other places. In my main.lua file, I have a storyboard.gotoScene(“start”) to come to this file and from here, for the play button, I have a storyboard.gotoScene(“game”) to go the game.lua file. 

If you’re using storyboard, why  not make your gamecredits a storyboard module and use storyboard.showOverlay(“gamecredits”) to show it and then have a close button that just calls storyboard.hideOverlay()?

Ok I will definitely try that out and let you know if it works. Thanks.

Bump.

Edit: delete

Couple of things…  We used to support a 3rd party service that used “credits” ad the name of API.  I think the way you’re using the variable “credits” is probably safe, but just to be sure, you might want to rename it to gameCredits or something.

 

I don’t see any buttons in your credit view to hide the credit view and show your other stuff.  How does it know to go away and show the other bits again.

 

I tried to make another touch function for the background that is showing in the creditsView so that whenever the user touches the background, it returns to the titleView. Inside the touch function, I tried storyboard.gotoScene(“start”) but that didn’t work and neither did me just making the objects in creditsView invisible and the titleView Visible.So I was wondering, what kind of code would I put in that would do that?

 

And thanks for the tip. Will change to gameCredits.

Your code above doesn’t show any hints that you are using Storyboard to manage scenes, so storyboard.gotoScene() won’t work unless you are using separate modules with all the required parts needed to make it a storyboard module. 

If you’re not using storyboard I would go back and try adding that touch/tap handler to the background of the credits screen, and then post your code back for us to take a look.

I am using storyboard in other places. In my main.lua file, I have a storyboard.gotoScene(“start”) to come to this file and from here, for the play button, I have a storyboard.gotoScene(“game”) to go the game.lua file. 

If you’re using storyboard, why  not make your gamecredits a storyboard module and use storyboard.showOverlay(“gamecredits”) to show it and then have a close button that just calls storyboard.hideOverlay()?

Ok I will definitely try that out and let you know if it works. Thanks.