11 Replies - 12248 Views - Last Post: 06 January 2010 - 06:22 PM Rate Topic: -----

#1 willn606  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-May 08

Pause screen

Post icon  Posted 10 May 2008 - 10:22 AM

What is the c++ code for making a pause screen for a game?
Is This A Good Question/Topic? 0
  • +

Replies To: Pause screen

#2 Renzokusen  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 99
  • Joined: 11-March 08

Re: Pause screen

Posted 10 May 2008 - 10:48 AM

View Postwilln606, on 10 May, 2008 - 10:22 AM, said:

What is the c++ code for making a pause screen for a game?


My teacher just recently taught us this.

system("pause");

Just copy an paste that at the end of your program before your return 0;

It should display on your program "press any key to continue" which when you do will cancel the program. So it is a very helpful little bit of code.
Was This Post Helpful? 0
  • +
  • -

#3 realNoName  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 343
  • Joined: 04-December 06

Re: Pause screen

Posted 10 May 2008 - 11:33 AM

system("pause"); does work but its platform specific and is not conform to the c++ standards


one way to pause the screen is use cin.get() and it does conform to standards
Was This Post Helpful? 0
  • +
  • -

#4 Renzokusen  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 99
  • Joined: 11-March 08

Re: Pause screen

Posted 10 May 2008 - 01:08 PM

View PostrealNoName, on 10 May, 2008 - 11:33 AM, said:

system("pause"); does work but its platform specific and is not conform to the c++ standards


one way to pause the screen is use cin.get() and it does conform to standards



Sorry didn't notice the previous question was referring to a pause screen for a game. I'd go with realNoName's example over my own because I think it would work better for your needs.
Was This Post Helpful? 0
  • +
  • -

#5 Codegamer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 04-May 08

Re: Pause screen

Posted 16 May 2008 - 03:49 PM

system("pause"); in the end of your code^^ :)
Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Pause screen

Posted 16 May 2008 - 03:54 PM

I agree with RealNoName, cin.get(); works with all platforms. Stick with that.

Also, I found something the other day, about the system function. It takes a lot of processing power compared to a standard function. EG:
cin.get() will just pause for input.

Whereas the system function, which is platform specific anyway, has to pause the program, call the OS, run the command being sent to the system function, wait for the input to that specific function, close the program being called, and restart your program. Bit of a memory hog, huh?

There were more steps to it, but you get the gist? :P
Was This Post Helpful? 0
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: Pause screen

Posted 16 May 2008 - 04:32 PM

You're all assuming that he talking about a console app. He said "game" and for the sake of disscussion I'll delve into a practice used for GUI apps.

Your game is run on cycles from WinMain. (Assuming a windows platform). Each cycle frames are updated, collison detection tahes place, keyboard/mouse input are considered, etc... In order to effectively "pause" the game when say the ESC key is pressed you have th stop the cycles for however long a period of time you want. This can be done by claling a self defined function

//stuff
void PauseAwesomeKickAssGameIMade(/*pass the handle of the game here, other stuff as well*/){
//Stop cycles for some time
//go back to game
}


This post has been edited by KYA: 16 May 2008 - 04:32 PM

Was This Post Helpful? 0
  • +
  • -

#8 drawa_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 10

Re: Pause screen

Posted 06 January 2010 - 04:36 PM

Hi, new here, and a serious C++ noob xP
You guys said that using cin.get(); was the best pausing method, but whenever I use it, it tells me that cin is an undeclared identifier and that .get must have a class/struct/union.
Like I said, I'm new, so I don't know what any of this means. Help?
I use Visual C++ 2008 if that helps.
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6053
  • View blog
  • Posts: 23,488
  • Joined: 23-August 08

Re: Pause screen

Posted 06 January 2010 - 05:24 PM

The Standard Library functions are in the std namespace, which is not included by default. Assuming you've included <iostream>, add using namespace std; after your included headers. Alternatively, you can use std::cin.get(); to just affect that particular call.
Was This Post Helpful? 0
  • +
  • -

#10 drawa_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-January 10

Re: Pause screen

Posted 06 January 2010 - 05:59 PM

View PostJackOfAllTrades, on 6 Jan, 2010 - 04:24 PM, said:

The Standard Library functions are in the std namespace, which is not included by default. Assuming you've included <iostream>, add using namespace std; after your included headers. Alternatively, you can use std::cin.get(); to just affect that particular call.

Thank you very much!!!
Was This Post Helpful? 0
  • +
  • -

#11 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Pause screen

Posted 06 January 2010 - 06:14 PM

// You may need to have this line first ...
std::cin.sync(); // 'flush' cin stream ...

// now will wait until 'Enter' key pressed ...
std::cin.get();
Was This Post Helpful? 1

#12 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Pause screen

Posted 06 January 2010 - 06:22 PM

There's a whole discussion on this very topic here. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1