Pause

23 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.17
List Price:  €95.97
You save:  €28.79
£55.84
List Price:  £79.78
You save:  £23.93
CA$100.80
List Price:  CA$144.01
You save:  CA$43.20
A$112.68
List Price:  A$160.98
You save:  A$48.30
S$95.16
List Price:  S$135.95
You save:  S$40.79
HK$543.23
List Price:  HK$776.08
You save:  HK$232.84
CHF 63.03
List Price:  CHF 90.05
You save:  CHF 27.01
NOK kr794.99
List Price:  NOK kr1,135.75
You save:  NOK kr340.76
DKK kr501.02
List Price:  DKK kr715.78
You save:  DKK kr214.75
NZ$124.35
List Price:  NZ$177.65
You save:  NZ$53.30
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,350.53
List Price:  ৳11,929.84
You save:  ৳3,579.31
₹5,987.45
List Price:  ₹8,553.87
You save:  ₹2,566.42
RM312.96
List Price:  RM447.10
You save:  RM134.14
₦108,274.53
List Price:  ₦154,684.53
You save:  ₦46,410
₨19,454.09
List Price:  ₨27,792.76
You save:  ₨8,338.66
฿2,378.12
List Price:  ฿3,397.46
You save:  ฿1,019.34
₺2,466.48
List Price:  ₺3,523.69
You save:  ₺1,057.21
B$432.51
List Price:  B$617.89
You save:  B$185.38
R1,311.95
List Price:  R1,874.30
You save:  R562.34
Лв131.43
List Price:  Лв187.76
You save:  Лв56.33
₩103,223.92
List Price:  ₩147,469.07
You save:  ₩44,245.14
₪257.31
List Price:  ₪367.60
You save:  ₪110.29
₱4,072.64
List Price:  ₱5,818.31
You save:  ₱1,745.67
¥11,041.56
List Price:  ¥15,774.33
You save:  ¥4,732.77
MX$1,420.31
List Price:  MX$2,029.11
You save:  MX$608.79
QR254.14
List Price:  QR363.08
You save:  QR108.93
P970.50
List Price:  P1,386.50
You save:  P415.99
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,560.93
List Price:  E£5,087.27
You save:  E£1,526.33
ብር8,897.26
List Price:  ብር12,710.92
You save:  ብር3,813.65
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$69,315.99
List Price:  CLP$99,027.09
You save:  CLP$29,711.10
CN¥510.87
List Price:  CN¥729.84
You save:  CN¥218.97
RD$4,256.60
List Price:  RD$6,081.12
You save:  RD$1,824.52
DA9,489.42
List Price:  DA13,556.89
You save:  DA4,067.47
FJ$162.54
List Price:  FJ$232.21
You save:  FJ$69.67
Q538.26
List Price:  Q768.97
You save:  Q230.71
GY$14,619.81
List Price:  GY$20,886.35
You save:  GY$6,266.53
ISK kr9,747.50
List Price:  ISK kr13,925.60
You save:  ISK kr4,178.10
DH704.68
List Price:  DH1,006.73
You save:  DH302.05
L1,290.62
List Price:  L1,843.82
You save:  L553.20
ден4,134.98
List Price:  ден5,907.37
You save:  ден1,772.38
MOP$559.01
List Price:  MOP$798.63
You save:  MOP$239.61
N$1,299.34
List Price:  N$1,856.28
You save:  N$556.93
C$2,571.30
List Price:  C$3,673.45
You save:  C$1,102.14
रु9,517.06
List Price:  रु13,596.38
You save:  रु4,079.32
S/260.20
List Price:  S/371.74
You save:  S/111.53
K283.61
List Price:  K405.18
You save:  K121.56
SAR262.83
List Price:  SAR375.49
You save:  SAR112.65
ZK1,933.89
List Price:  ZK2,762.82
You save:  ZK828.92
L334.30
List Price:  L477.59
You save:  L143.29
Kč1,691.03
List Price:  Kč2,415.86
You save:  Kč724.83
Ft27,618.75
List Price:  Ft39,457.05
You save:  Ft11,838.30
SEK kr770.19
List Price:  SEK kr1,100.32
You save:  SEK kr330.12
ARS$72,002.55
List Price:  ARS$102,865.20
You save:  ARS$30,862.64
Bs482.86
List Price:  Bs689.84
You save:  Bs206.97
COP$308,627.53
List Price:  COP$440,915.37
You save:  COP$132,287.84
₡35,480.70
List Price:  ₡50,688.88
You save:  ₡15,208.18
L1,775.44
List Price:  L2,536.46
You save:  L761.01
₲544,980.94
List Price:  ₲778,577.57
You save:  ₲233,596.63
$U3,110.44
List Price:  $U4,443.67
You save:  $U1,333.23
zł287.20
List Price:  zł410.31
You save:  zł123.10
Already have an account? Log In

Transcript

Hello, in this video we are going to cover implementing a poor system into our game. If we go over to our game screen, we can play the game, play some pieces, and we'll eventually get a game on the screen. But what we want to pause the game and go to the main menu or retry, we're going to be implementing all of those cool features right now. So first of all we want to do is go to the definition file. And there are a few definitions you need to add. There is one for the pause background.

And this is gonna be the same as Game Over background which is actually called for background. So this allows us to use different backgrounds if we want to add a later date. We need one for the pools window. If you which I'm guessing you have watched the game over video, then we you will know what each one of these are for If not, we'll show you very soon. You will need So I'm defined for the pause button and the Resume button. So the first one is going to be pause button and jamis two pause button this one as well.

Now, this will be the zoom button so the pause button will display on the game screen where you'll be able to click it and the Resume button will be displayed on the actual pause menu. This is gonna be called resume. resume. And now we can just scroll down all the way to the bottom. And what we need to do is just create a fade in time for the pause background is gone. To be the same, but you can easily change it because we'll have different different definitions.

So next, you want to go to the UI header. And in here, we want to create a few private methods. The first one is going to be void poor game, we can just duplicate this to save some time. So this will be called code when we actually press the pause game button needs to create some variables. We're going to keep track of game state. We are going to have a code close to the menu which is always going to be present pause menu.

We're gonna have a sprite which will be the poor background so pause. Background ground Now if we go to our I see one more change I need to make in here in the constructor, we need to accept in a reference to the game state. So we can actually keep track of what the game state is. We don't want a local instance, we want to know what the actual game state variable is in the game scene. Go to UI dot cpp, we can actually start implementing this now. So the first thing is if we go to the constructor, we need to update this so we'll say int game state.

We just set this game state equal in to game state. Like so. Now we need to create a variable for the soil for the screen so I should say screen size people director get instance Get visible sighs well now we need a vector to for the origin direct get instance get visible origin like so. So first of all we're going to create a menu item sprite for the pause item. So menu items quote pause item equals menu item sprite create and for this we will need the one with that is fine we'll actually be using the one with three different sprite parameters and a callback URL Once I can easily change it if you have a disabled button for whatever reason, you can easily change that right. So this is going to be stroked, create pause button.

And this is going to be straight create pause button pressed. And bright creative entrepreneur this the poor button for the disabled one, but you can put wherever you want to. You could have a separate one if you did want to have a separate one. Now we're going to do cc underscore callback one. And we are calling the pause game method. target to this like so.

Now we're going to set the position of this pause item. So pause item set position and this is going to be back to for the x axis we want to get the screen size, the width minus the pause item. Calculation I need to do here so I'm actually going to enclose this in brackets. This is going to be Paul eater. Get content size dot width it void up by two. So this is just going to allow us to position it all the way to the right on the screen because we are moving it by the screen size width because it's on the left side next to the right side, I will just move this slightly to the left Otherwise, it will be half on screen and well half not on screen.

And well we just need to factor in the origin now. So plus origin dot x. And now we need to do something very similar for the y axis. We could actually just copy and paste this. If we copy and paste this changes the screen so you've got a height, pause it Hi. This is going to be a why everything match up in terms of the why of going back to those stupid Okay, that is good.

All good stuff now. So now what we're going to do is create a menu and this menu, aspect menu buttons equals menu, colon colon create. fourth item is going to simply consist of only one item or the item when the menu button set position and the position we're going to set it to is back to zero because we are overriding the position ourselves. So we Just want to set it to 00. So we can just position it ourselves without the menu doing any other positioning dairy wants to. This is a great way of making sure if future compatible, because maybe the Coco's team changes the initial positioning of menu but we set it to 00 every single time and then manually changing ourselves instead of just factoring in our position in with their current position, or just making more dynamic this way.

So we're gonna do layer and the layer we're gonna add or the child is going to be many buttons. Now we're going to create the call pause background. So pause, background equals white, colon, colon create. And this is going to be pause but grand gonna have pause. backgrounds the position of the position can be very simple, can we still not focus out to you why colon colon gets green center and we're going to do Paul's background set opacity to zero we're gonna fade in so it looks nice. So in the child porn background, we don't initially fade in you then some sort of action.

We'll do that when the actual pause button is pressed. And again, we only want to show it when the game is paused not any other time. But now we're going to create the actual pause menu. So menu, item image, as strictly asterik overlay pools menu item equals menu item image and it's going to be created from the pause Windows file path. need it for the free difference stayed steady come in. So with this is the same one just allow you to easily change later on.

No not calling any callbacks. Now we're going to create the Resume button. So menu items thrive. Resume item equals menu items bright colon colon create. And for this we're going to put sprite create and this is going to take a parameter of Resume button for this duplicate this pleased to hear from you in Baton score press. You're gonna have one for the disabled one that kicked out of the scene but could have a different one if you want to do.

And now we actually need the callback method that we're going to be calling when this button is pressed. So CC, underscore callback one. And this is going to be UI, colon colon pause game. And so the target is going to be this. Like so. Now we need to set the position, that position positioning, review item, set position and for the position, we're gonna do that too.

And this is gonna be very similar to what we did for the other items in our menu down here, you know what, I could just copy and paste this code here, save some time, you should already know it. If you don't, I'll briefly explain it. If I put it here, I could have done it for this as well in all fairness. So this is overlay paused window item. I'm going to put this as a minus so this will be to the left of it, that a retry item is going to be resume item. And that's all good now, so we can now just update this and do the main menu item now.

So Main Menu, item. Copy and paste that here. And here, and for the button, we're going to use the home button that we used in the previous video. Yo. So home button on school pressed, like so. And now we just need to construct our pause menu.

So pools menu equals menu colon colon create overlay for the window item, review item and main menu item, all very simple stuff. Very similar to what we did before. Now we just need to set the position and for this again, it's going to be off the screen so we could just copy the code for this again to save some time. So if I copy this paste this bad boy here And this leads to obviously the pause menu now, the only thing now we need to do is add it to the child for layer, child pause menu. And now what we can actually do is implement the different methods. So we got retry and go to Main Menu.

We actually need the pause game method now. So we can just duplicate one of these. So pause game. Just want to make sure we are calling the appropriate call Back methods and our from here. No, it's not look like it's so for the resume item. That's looking good, we should be calling in the pause game.

But for the main menu item, we need to call the go to Main Menu, which we already implemented in the previous video. Very simple method just create a theme. Very simple and very similar to what we've already done. So we're going to get rid of all of the contents and the pause game so far as many lines so we can easily move around and create a size of screen size equal to director, get instance. Get visible size, like so. And now we're going to check what state the game you're in.

If it's in the plane state. So this is the game state variable that we have locally stored, but it is the it is a pointer to the actual game state. So it's not a local copy. If it's playing, and we actually want to, you know, pause the game, if it's not, if it's already paused, we want to well on boarded, so if the state is paused, then we will unpause it. So now let's implement the code that we want to do. Game state equals state.

Pause. So now the game have been paused. We're going to do pause, background run action fading, create Hold on scope background fade in time. And now we just need to bounce the menu onto the screen. So for that, we're just going to do ease. Bounce a, you can use any sort of an emotional, transitional, whatever you want, will provide you with a link to the Coco's API guide that we created, which shows you with Jeff's all the different animations and transitions that you can use for stuff with scenes, moving objects around all of that good stuff.

So this is going to be called menu action even equals these bands out, create. And for this one we move to, so it's going to move to the center the screen for the duration is going to be menu on the school move bans duration. And for the position like I said, it's going to be the screen center. So sonar Coco's help UI colon colon get screen center. And the last thing we need to do is pause menu and actually run the action. So run action, menu, action easing.

And now that's all done for pausing it. So to resume it again. If we copy and paste this code, this changes to State Plane. So instead of fading in now we're going to fade out. So using the Fade In time, you could have different times, but consistency is key. Instead of having the whole second fight in, two seconds fade out, it just wouldn't look very consistent.

And very good. So for the action easy, this is gonna slightly change because we don't want to move it to the center of the screen, we want to move it off screen. And we can do that by getting the initial code for positioning it. So where is it? Right, Tia. So if we copy and paste this, go down here.

Replace this with here. And that is it. So in terms of running the action, that doesn't change, there's only one last thing that we need to do now. Go to game scene dot cpp. And we scroll up where we actually initialized our UI object. We just need to also pass in the game state.

So game state, run this bad boy, and we should have a game ready to play with AI With Game Over stakes and a pause system now as well. Okey dokey. So this is loading up click Play pause button in the top right. Let's see if I place a piece. Now if I click pause, you get the poor. Okay, that's messed up.

But there's just a simple position and issue. So go to the top and go to the main menu item. Don't negate this one, this is a positive so it moves to the right of the center of the actual paused menu. So this let this build which is successful. This is done running again and we should have a pool system that looks better now. Play plays a PC press pause bounces on by Click pause or resume it goes back and I can continue playing so if I pause you can't do anything here like so as you see nothing has been placed it's not last complacent thing here.

And if I click the home button was it nine or was it just not? looks okay to me that was very weird. Looks fine to me, so we can go to the main menu. So that's it for the poor system. If you have any questions, feel free to post them on my education platform. So now learning duck odk or reach out via Twitter or Facebook comments, however you feel comfortable, there will be links available to the code cost API guide that we discussed and the GitHub page.

In the next video, we are going to cover achievements and we'll be wrapping up this series. So 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.