Hello, welcome to the 16th tutorial in the cocoa studio, the c++ series. In this part we'll be looking at save the score. We'll be continuing on as usual from the previous part of the series. If you don't have the source code for that, don't worry, there'll be a link in the description to the source code. Okay, we can play a game that allows us to earn points and display the score on the game. Obviously, it doesn't check out so score against the previous score, and doesn't provide any saving functionality which the original Flappy Bird does.
Fortunately, saving simple information such as a high score, it's really easy. In our game, I've seen a CBP job before we print out the scores. We will love the previous high school so basically now in the game, I was in that game scene. Yeah, literally here just before this will be checking. We'll load up the previous school. First we will create a user default variable that allows us to read and write data from the storage area, this is the work for iOS and Android.
We don't have to say why iOS do this and Android do this, try and get this direct trade. We just use this bit of code, like sprites, pretty much. So we're going to use float. And it's going to call it depth equals user default color comma shared view the default it's known in that it is deprecated. I believe the non deprecated version in get instance. There we go.
You will narrow it with the old school Buffy to like this. We will just have zero water or ice go equals F get integer for key I'm going to use a default value or aka if you can't find default value will just return the value that will specify which will be zero. And for this, we're going to look at the ind for high school. This isn't shared between application so your application will have a separate area for storing data. So if you have high score and you have another application called essays, getting get data from high school, it will be unique, which is pretty cool. So for the default value locks, zero, semicolon.
Now we will check if our current score is higher than the high school and if it is the high school will be updated and saved. So don't do pace. Gold is greater than high school. We will say High School and that equals score. def. Set into the 4k.
And for this we just put High School make sure it's the same as this. What we could do actually Amelie Our next task for you is actually abstract this into a hash define that way you can easily change it if you need to do the sort of stuff which really make use of definitions. Same with paths as well like this, this plug in and leave that for you. And for the valley that we're going to save with a poor High School semicolon. I'm finding listening to end user default file we need to flush it so let's do d f. flourish run into this when you're finished with it, it can create a new one and nothing stopping you from do that. Finally, we'll create a high score label similar to what we've done here.
To display the high score basically 700 underscore underscore string. class to temp, voice go to posts go to equal underscore underscore string colon colon create with format format when to put percent or a high score semi colon, auto high school label equals label. Tt create and without going to create with temp, boys school, get C string and for the Font Name we're going to do the same appear so that is formed for slash mark out TT here. And now for the side we're going to be visible foid dot height score form size. Luckily what we've done here so it's dynamic a, the size looks good on different screen sizes aka retina non retina for example. And now what we're going to do is do High School labor Set color.
This is just so we can distinguish the regular school and the high school two color three, a yellow and a high school label. Set vision point the board up with the point seven five plus origin got it for the wildland the visible size dot height divided by two or three. Why? And what we've done here here we positioned in 25% among you position the high school labor now set foot center long so it's been the high school I mean, the current school level will be on the left Costco labor will be on the right turn. Now the last thing to do is add This label of a child the layers of high school label. Actually, you know what I will do that no particular reason why I'm doing this Tom's gonna call this high school floppy.
Again, there's literally no reason why I am. It's just something that I've found like doing and I will click play. Once you run which we had to play again, when we get some school if it's greater than our current high school or our previous High School, it will load it, save it and it will display the scores accordingly. So this is loading. Let's just wait for a moment. Sorry about that.
Okay, here we go. The playbook So let's score a point or another point, and then that's done on purpose, we get to two, if we click retry, and it's going to die without actually scoring a point I think zero to the previous go ahead and say but now in the Maquis beat my score to seven This is get free and I'll probably die after that. And then you can see that he will update the score. Get for one there we go is updated the score and score our current score. That is it for this tutorial in the next part could we are almost done with this game. Got one nothing to do and that is to add orders at the moment.
It's very dry. Obviously there's no signs going up. I sometimes will have make it a lot better. But that's for the next part of the series. If you have any questions, feel free to message us at support at sonar systems. Dakota, UK the email will be in the description.
Can comment on this video with direct messages via YouTube, or the recording for source code will also be the description and as usual, thanks for watching and I hope you have a great day.