Hello, welcome to the 14th tutorial in the cocoa studio Flappy Bird C for theory, and in this part we're going to look at explain score. We'll be continuing on from the previous parts in series. So if you haven't done it or you don't have the source code for for whatever reason, don't it'll be a link in the description. And let's just go ahead and open up our project down here, okay, we now have a game that you can play and end points and the score is displayed on the game scene is just printed out sort of in the log, but that's not really what we want, or the game obviously once the player dies, we will now be displaying the score on the game thing in this tutorial. Usual we will create a hash define as they are really amazing. This will be the school's font size.
So when you hash difference on the score, font size 0.1 again, we're gonna be factoring in screen size. usual lesson I declare a label for the scoring game scene. So let's go down here under cost to D label as true global label. And then we're going to go to a game scene dot cpp for we can use a score, we need to create a string of the number. And we can specify a roll number in a label. So if we just go down here, and we're going to use the caucus to the string which is underscore underscore string, field regular string that belongs to the standard name with AK it's not caucus to dx related so code has to dx to get around it.
They put on the score on the score in front of the keyword think. So, Tam score, you might be wondering, I'm just gonna talk about something else for a second. When they're done that with string Why haven't they done it with something like sprite, for example. And the reason they have his y on the screen now is going to be sprite, it'd be Pro isn't built in to Coco's. I mean, it's not built into c++. Whereas string is whereas I you can exploit it in obviously frameworks but their stuff on top and there's only so much you can do to try and prevent frameworks on top that you don't know of getting confliction like with naming services, initialize this underscore underscore strength con create with former, you might be thinking why I'm using on underscore so string instead of auto auto keyword would work just as good recently, I'm using underscore and so string is a so you are aware that it is on sort on the source string and not just a regular string.
It's just so you're aware of that but in the future if you want to use the keyword auto def a, okay, so we're gonna put percent I score. Let's now initialize the score label. Make sure the form for is added to the Resources folder. So if we go not, they don't want to scroll down if we scroll down here we got iPad iPad HD iPhone, iPhone, HD, HD, five, mountain, and sand but no fun. So we're just going to show and find out. Can we actually have a font folder here with the speed and default font that we've got mock self dot TTF.
Let's drag and drop the resources. Add the usual quick folder referencing finding added folders. editor Matt target, why not? And what we're going to do now is score label equals label. Conan Conan create with T TTF. And for the text, we're gonna put temps go get C string, and then for the form we're going to put fonts for slash Mark TT F, then for the font size one visible size dot height, I'm going to turn that price.
Go font size. So now you'll be relative to the screen size. If you were only on the retina, iPad or a regular iPad, or even an old iPhone, they will look very similar instead of just literally being physically the same size, which obviously you don't want. Now let's set the color which will be white. In this instance, we're going to do school label color, the color we do color three, k konkan. Now within the set white, we can set we can set RGB values as well if we want to, we will now set the position on the score label.
So we'll call label set position for this point. More than the visible side. Don't give birth to origin x. They're not divisible. Sorry, the height fine but their point seven five aka be free quarters along in the y axis, plus our agenda or y. And there's this core level cannot be added to the scene as a child.
So if we do this child school label and was going to make sure it's on top of everything I was going to run this though we still got two last things to do. But we'll do the afternoon ran the application so you can actually see working and what issue at the moment you may have guessed it but for this Hang on a moment. That low which the simulator first Don't get me wrong, it's still pretty good. could fit happy, healthy for you the answer? simulator emulator is terrible. You just don't want to use an android emulator or the iOS simulator, you can get away with it.
Okay, and we click play. And it seems that the school we scored a point, but it didn't obtain the rater update. So but the old text, so we need to go back here and we need to update the text and we'll do that whenever we score a point. So okay here. So we'll actually naturally copy and paste this line, because we need that right here. I think it's pretty new temporary score string variable during underscore label, set string, and we'll just do 10 school.
Get see strengths and weaknesses To move this point cc low point score ninth, we don't really need it. And we can do this as well. So now if we run this play play, and we have zero so let's uh, score a point. And it's updated to one, two, and three. So there we go, we have a scoring system network score systems actually display the scores. That's it for this part of the series.
In the next tutorial, we'll be looking at displaying the score on the game of a scene. If you have any questions feel free to message us a sport a sama systems Koto, UK, the email will be in the description. You can comment on this video or just directly messages via YouTube. All the compiling for source code will also be in the description. And as usual, thanks for watching, and I hope you have a nice day.