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.18
List Price:  €95.97
You save:  €28.79
£55.85
List Price:  £79.79
You save:  £23.94
CA$98.21
List Price:  CA$140.31
You save:  CA$42.09
A$107.62
List Price:  A$153.75
You save:  A$46.13
S$94.24
List Price:  S$134.64
You save:  S$40.39
HK$544.83
List Price:  HK$778.36
You save:  HK$233.53
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr774.97
List Price:  NOK kr1,107.14
You save:  NOK kr332.17
DKK kr501
List Price:  DKK kr715.75
You save:  DKK kr214.74
NZ$119.95
List Price:  NZ$171.37
You save:  NZ$51.41
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.58
List Price:  ৳11,945.63
You save:  ৳3,584.04
₹5,909.84
List Price:  ₹8,442.99
You save:  ₹2,533.15
RM312.71
List Price:  RM446.75
You save:  RM134.04
₦118,484.88
List Price:  ₦169,271.38
You save:  ₦50,786.49
₨19,443.22
List Price:  ₨27,777.22
You save:  ₨8,334
฿2,412.28
List Price:  ฿3,446.26
You save:  ฿1,033.98
₺2,418.32
List Price:  ₺3,454.90
You save:  ₺1,036.57
B$406.01
List Price:  B$580.04
You save:  B$174.03
R1,270.71
List Price:  R1,815.38
You save:  R544.66
Лв131.35
List Price:  Лв187.66
You save:  Лв56.30
₩98,301.65
List Price:  ₩140,436.95
You save:  ₩42,135.30
₪260.01
List Price:  ₪371.46
You save:  ₪111.45
₱4,125.14
List Price:  ₱5,893.31
You save:  ₱1,768.17
¥10,832.35
List Price:  ¥15,475.45
You save:  ¥4,643.10
MX$1,429.79
List Price:  MX$2,042.64
You save:  MX$612.85
QR255.18
List Price:  QR364.56
You save:  QR109.38
P956.90
List Price:  P1,367.06
You save:  P410.16
KSh9,061.51
List Price:  KSh12,945.58
You save:  KSh3,884.06
E£3,475.01
List Price:  E£4,964.52
You save:  E£1,489.50
ብር8,566
List Price:  ብር12,237.67
You save:  ብር3,671.66
Kz63,900.87
List Price:  Kz91,290.87
You save:  Kz27,390
CLP$68,444.99
List Price:  CLP$97,782.75
You save:  CLP$29,337.76
CN¥506.93
List Price:  CN¥724.22
You save:  CN¥217.29
RD$4,217.06
List Price:  RD$6,024.63
You save:  RD$1,807.57
DA9,397.90
List Price:  DA13,426.15
You save:  DA4,028.25
FJ$159.29
List Price:  FJ$227.57
You save:  FJ$68.27
Q540.13
List Price:  Q771.64
You save:  Q231.51
GY$14,638.82
List Price:  GY$20,913.50
You save:  GY$6,274.67
ISK kr9,773.54
List Price:  ISK kr13,962.80
You save:  ISK kr4,189.25
DH703.91
List Price:  DH1,005.63
You save:  DH301.72
L1,275.33
List Price:  L1,821.98
You save:  L546.64
ден4,132.76
List Price:  ден5,904.20
You save:  ден1,771.43
MOP$561.01
List Price:  MOP$801.48
You save:  MOP$240.46
N$1,268.91
List Price:  N$1,812.81
You save:  N$543.90
C$2,574.70
List Price:  C$3,678.31
You save:  C$1,103.60
रु9,449.77
List Price:  रु13,500.25
You save:  रु4,050.48
S/265.32
List Price:  S/379.05
You save:  S/113.72
K281.71
List Price:  K402.47
You save:  K120.75
SAR262.77
List Price:  SAR375.40
You save:  SAR112.63
ZK1,934.92
List Price:  ZK2,764.29
You save:  ZK829.37
L334.42
List Price:  L477.77
You save:  L143.34
Kč1,702.59
List Price:  Kč2,432.37
You save:  Kč729.78
Ft27,646.05
List Price:  Ft39,496.05
You save:  Ft11,850
SEK kr772.42
List Price:  SEK kr1,103.50
You save:  SEK kr331.08
ARS$70,251.41
List Price:  ARS$100,363.46
You save:  ARS$30,112.05
Bs483.50
List Price:  Bs690.75
You save:  Bs207.24
COP$307,238.59
List Price:  COP$438,931.09
You save:  COP$131,692.49
₡35,641.51
List Price:  ₡50,918.63
You save:  ₡15,277.11
L1,768.23
List Price:  L2,526.16
You save:  L757.92
₲546,248.87
List Price:  ₲780,388.98
You save:  ₲234,140.10
$U2,983.14
List Price:  $U4,261.82
You save:  $U1,278.67
zł291.40
List Price:  zł416.31
You save:  zł124.90
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.