Implementing The Main Menu Scene

9 minutes
Share the link to this page
Copied
  Completed
Let's implement the main menu scene to provide navigation to the game scene.

Transcript

Hello, welcome to the fourth tutorial in the compass to the ex Flappy Bird c++ series. And in this part, we're gonna be looking at how to implement the main menu thing. We'll be using the source code from the previous part which we implemented as glassing, we don't have it, don't worry, they'll be a link in the description to the source code. So this thing will be pretty simple with three main key elements. There'll be the background image, which you will be interacting with, there'll be the title, which again, you won't be interacting with. And there'll be a play button, which obviously will be interacting with and when you click the play button, it will take us to the game scene which you prayed to I hear there's no actual functionality yet, but it is there.

So the first thing we're going to do is include the game scene and the definitions header. We can do that up here right? On the void scene. It'll be a main menu thing. So here's can do hash clued gains seen slash definitions. Now let's add the background image.

So we're just going to go to the init method. And down here, we're going to do auto backgrounds. Bro equals broad colon colon create chrome dot png and then set the position in the backgrounds by a sprite and that's just going to be centered. So, set position. So, two point visible size dot width divided by two plus origin dot x, visible sois dot height 2.2 plus origin dot y. And the final thing we're going to do just add some of the add this sprite to the layer a child specified backwards Polaroid, now it's going to run it as well.

So just to make sure it's all working as we go along instead of doing it right at the end. So that's just some good techniques that you should employ when coding and designing in general test as you go along. So the splash screen that disappears and now we've got deep backgrounds bright. Then next step is let's now declare the function that will be called when the play button is pressed, which isn't added yet, though but will be soon. So if we just go to the main menu scene, the haich D approach, also need private method, private, void go to gaming scene and this takes a ref us to arrest last needs to be close to the photon cola. We'll call it sender.

And now let's implement the go to game using finger sock and copy and paste it from here. So it's a little quicker there is any cola issue, main scene, Chrome colon, four curly, brace it and now that's the bare bones implemented, let's actually implement the full code. So we're gonna do auto scene equals game scene. con con create a thing that was gonna create a local instance of gaming. They were going to director common common get instance. Replace theme in here with the true mission fade.

Of Comic Con will create and for the duration of Apart from Vish underscore time she specified in the definition false, we'll just keep using it. The seeing just specifies seen, I can get rid of this color values will not be using that replacing. And now that's the go to gain team method implemented. Again, this function uses the transition time. And if we want to change the time, we just go to the header file and change it. We could also abstract code such as the transition type, which is this right here.

If we really want to we can sort of abstract that, but it does an extra test to see if you want to do that. The last thing to do that is to create a menu where the play menu item, and when it gets clicked, it will take us to the game scene. So what we're going to do is here or to alter, input menu, item image, column column, create Played button dot png with G then which is right here will show you there, we need to also specify the correct version of Play Button dot png Play Button clicked. And then the laughing will have specified the function that will be called when it's clicked. So with a string cc on the school callbacks, and these numbers basically specify how many parameters this method takes. Because this method takes one parameter, we just do the CCM scope callback one and I specify the selector aka the method.

And for that we just do Main Menu using the colon colon go to game scene, and for the target, we just put this The next thing to do is position the items are placed into set position. Feel like I'm missing something? Yeah, we're missing a title. Okay, we'll add the title in a moment. That's forgot all about that then. So what we're gonna do, and so this is the play item here, and for the position will be point.

Musical size dot width, divided by actually, I'm gonna copy and paste this entire thing, as that will be a lot easier. In the semi colon at the end, and so, we're going to do alter, menu equal many column create. query with a play turn. No Menu set position for the position when it's going to point column column zero because we've set the position to the individual items Finally we can add this as a child to the layers menu now we can run this once So once we've got this running successfully what we're going to do is finally add the title should did just forget something that the play button and click it and it takes us to the game thing so the last thing looks and add a sprite here so autumn title sprite people's sprite conical create and it is called title a PNG also dot png and then title sprite set position point for this For the x axis system centers have variable size dot width divided by two plus origin dot x.

And then the y axis what we're going to do is we'll put size dot height and then we're going to do minus total Sproat get contents sois dot white basically is coming position towards the top was just gonna be had below you'll see in a second and Finally, add this show your top tools broken ironic in theory, you could encompass the tortoise, bro within the menu heavy, heavy add the noi term. And then for the clicked image, you could specify the same for me so it looks like it's not being clicked. And also we don't have to have a callback barfing. This is probably a little easier. So we've got this. Clicking off the app and background nothing happened.

When we click the play button. It shows us the click button and take To the game team. That's it for this quarter series. In the next part, we're gonna be looking at the Games in background. If you have any questions, feel free to message us or support us on our systems code. Okay, the email will be in the description you can comment on this video or just directly messages via YouTube, or the require link for source code will also be in the description.

And as usual, thanks for watching and I hope you have a great day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.