Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Any idea for Pause?

Author
Message
Hello Everyone !
14
Years of Service
User Offline
Joined: 1st Sep 2011
Location:
Posted: 10th Nov 2011 14:10
Hi guys. Its me again I dont have any idea how to make pause for my game. For example is, when I press the Escape key my screen will turn into something dark and all the moving objects will stop. Any help will be much appreciated.

i have a problem in darkbasic codes. pls help me
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 10th Nov 2011 14:55
You need to jump into an other loop with sync in it, and this loop would contain nothing but the options for returning to the game, or escape totally.

Works completely fine if you only have 3d stuff in your game, but if you use 2d of any kind, you need to draw those in this secondary loop as well before the sync command.

-In.Dev.X: A unique heavy story based shoot'em ~35%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
YavinB
16
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Ontario, Canada
Posted: 13th Nov 2011 04:38
Hello! You can use this code to pause the game. Not exactly sure if it works for 2D games, only tested it on 3D.



It will pause the game when the user presses 'escape' key, then when the user presses the '1' key in the pause menu it will go back to the game.

Hope this helps.

-Mike
Hello Everyone !
14
Years of Service
User Offline
Joined: 1st Sep 2011
Location:
Posted: 13th Nov 2011 06:14
Wow thank you Guys!!! It really works. Thanks a lot. GodBless

i have a problem in darkbasic codes. pls help me
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 13th Nov 2011 10:34
If you're using a timer based movement function in your code, you can usually alter the TBM_function to accommodate a pause in your game.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Jamie_Leigh
14
Years of Service
User Offline
Joined: 15th Dec 2011
Location:
Posted: 15th Dec 2011 15:48
Hi guys, I'm very new to darkbasic pro and I tried putting this code into a simple platform game my teacher gave me but it just closes the game still.

I tried putting this code at the bottom of the original code, does it need to be placed somewhere specific?

Thanks alot!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Dec 2011 20:44
did you forget the disable escape key command?

Jamie_Leigh
14
Years of Service
User Offline
Joined: 15th Dec 2011
Location:
Posted: 16th Dec 2011 13:58
I just copied and pasted it into the game code :S
Jamie_Leigh
14
Years of Service
User Offline
Joined: 15th Dec 2011
Location:
Posted: 16th Dec 2011 14:03
It's telling me "Compilation Failed (syntax errors)" and is highlighting the code:

"If inkey$()="1" Then Gosub game"

Thanks
YavinB
16
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Ontario, Canada
Posted: 17th Dec 2011 23:59
Hello Jamie, assuming that this isn't a compiler error, it sounds like somewhere in your code you put the pause code in the wrong spot.

The code I originally posted was meant to be split up into parts. That code is normally split up like this:

Pre-Game
Game
Post-Game

The Pre-Game code is before the first DO-LOOP command. That area in the code is where you usually have all the resources getting loaded and the values declared. If you're using your teachers project still, it shouldn't be hard to make with the pause function.

Before the first DO command, you'll want to disable the escapekey so that you can't exit the game by pressing escape. Use this code:



After adding that code, you need to declare the game and declare the pause is off. All you have to do is add this:



right above the DO function.

Next thing you need to do is the Game section of the code. Inside the DO to the LOOP part of your code, you probably have all the controls for the game and the collisions, actions, etc. Right above the LOOP function, you'll want to add the code if you press the Escapekey that it goes the the Pause part of the game. Use this code:



Lastly, you need to add the pause part of it in the Post-Game section. At the bottom of your entire project, add this code:



I hope this helps out. If you have anymore problems with it, don't be afraid to let us know.

Also, If you still have the code that didn't work in your project, remove it before you try this.

-Mike
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 18th Dec 2011 05:12
Wow... I think this will be useful for me... so just tagging in,

However as my brain is alight tonight...
question...
Is it possible to use a 3d menu? like where you pause the game and the menu pops up but the camera in the background starts to spin around the Y axis slowly in the background? ( background can maybe have some image load into the menu with transparency or someting...)

[Hope this was constructive somewhat]

umm concerning this code



how does it know to return to the main loop?

YavinB
16
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Ontario, Canada
Posted: 18th Dec 2011 20:44
Hello, It is possible to do what you're saying. Once you use the Gosub command, you're leaving the current loop that you're in. If you're in the Game loop and you use the Gosub command to go to the Pause loop, everything in the Game loop pauses. In the pause loop, you would make the camera go around the player or whatever you choose to have it do. The only flaw with this is that when you exit the pause loop, it affects the Game loop. So the way around this would be to declare positions, angles, etc. of the objects/cameras/etc. that you're editing. Example:



If you declare that at the start of the code, and used this:





when you go to the Pause function, you'll be able to just position the camera and set the angle to where it was before.

This may seem hard, but it isn't too hard to do. If you want an example of it working, try this:



The code worked with my version of DBPro, so it should work with yours too. Hope that answers your question on it, or atleast most of it.

If you want it to go around the person, you'd have to add some more code to it, but this was just an example.

As you said about this code:



That code works by checking if the 1 key is pressed and if it is pressed, it will use the Gosub command to go back to the game.

The gosub command goes to sections in your code. You can declare these sections by using something like this:

ThisSection:
Hello:

They work by having letters followed by a : to define it. When you use Gosub, it will look for the section in your code and then go to it and exiting the current section it is in. In the full code, it shows

Game:

and

Pause:

Hope this helps out.

-Mike
Jamie_Leigh
14
Years of Service
User Offline
Joined: 15th Dec 2011
Location:
Posted: 18th Jan 2012 16:04
Thankyou very much YavinB,

Our teacher has now given us a version with a pause menu already coding it but it only consists of the game freezing with a message saying go back to game scrolling across the screen.

I am wondering if there is an easy way to change this to a screen only showing a graphics I can create in lets say photoshop that will tell you to press 1 to go back to game?

Thankyou
YavinB
16
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Ontario, Canada
Posted: 19th Jan 2012 00:54
Hello again!

If I understand what you're saying (Pause menu with an image telling the user to do something), it is quite easy to do.

First thing you want to do is load the image you made:



Change "file" to the file name of it (if its located in like, My pictures, set it to that directory eg. C:\Users\Mike\Pictures\my_bkg.bmp) and also change the ext to the file extention that you saved the image to.

Also, you may need to change the image number of it when loading. You may have already loaded an image with an image number of 1.

Now for part 2, there is 2 ways you can do this:

1. Make the image a sprite (I reccomend using this)

2. Pasting the image

For #1:

If the image isn't the exact same size as your game, you should use this.



Just change the sprite number to the sprite you want, and the image number to the one you loaded.

For #2:

If the image is the same size as your game, you should use this.



As you probably know, just change the image number to the one you loaded.

With whatever one you choose, make sure you have the code that will go back to the game with the code up there.

Hope this helps. If you have anymore questions, don't be afraid to ask.
Ramon156
14
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 2nd Apr 2012 18:11
Thank you this is just what I needed.
I use this method to enter the gunshop of my game.
Here is my code.

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 2nd Apr 2012 22:05 Edited at: 3rd Apr 2012 10:28
Here is a pretty quick example of handling pausing / menus using functions which I find preferential to gosubs.



[Edit]Realised I had left some "double slash" comments in. I prefer to use them but the syntax highlighter on here doesn't. Changed them to "rem".[/Edit]


Previously TEH_CODERER.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Apr 2012 04:59
Andrew_Neale KUDOZ! TO YOU!!!

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 3rd Apr 2012 10:26
Thanks, hopefully it will be of help to someone. I'm quite happy to expand on it if anyone wants.


Previously TEH_CODERER.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Apr 2012 10:27
simples, as I mentioned before... the camera in the background moving around ^^

and also keypresses for different menu text

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 3rd Apr 2012 10:37
Well the following code in the 'updateMenu()' function controls the camera whilst in menu mode.



At the moment this makes the camera spin around to point straight at the player but move off to the side a bit. This was with the view of the menu having an inventory so as you changed items around in the inventory you could see them updating the player object. To change this to simply make the camera rotate in the background is quite simple.



As for the menu itself, I'm afraid I have just started work so that may have to wait until I get home tonight but I will look to add the menu to this example then. Probably around 10 hours until I get home though, sorry!


Previously TEH_CODERER.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Apr 2012 11:05
no rush there buddy ^^

than you this may give me a head start when I start looking into my games soon... currently beginning the GDD stage

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 3rd Apr 2012 22:33
Got home from work and my washing machine flooded my kitchen. *facepalm* Lost some time sorting that out but here is a very quick menu implementation to the original example. It is nothing special but hopefully has some value, lol.




Previously TEH_CODERER.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 4th Apr 2012 05:55
Ah bugger... who put too much suds in lol

As I said take your time dont rush anything

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 5th Apr 2012 01:34
I usually do something like this, which is a cross between Andrew and Yavin's methods.


Even my simple example takes a while to see the flow so I'll give diagrammatic versions of all three.

Andrew's Method

The only job of the main loop is to decide where to send the flow.
This is a very good approach if done properly, the trick is not to just bundle your entire game into one function. For a demonstration it's okay of course but one would assume that if Andrew used this to make a proper game he would add separate functions as the game grew in size. Using functions of course means you can have separate files too and not crowd your workspace.

Yavin's Method

Yavin uses two loops and jumps between them. The only problem with this is it becomes hard to follow when the program gets big.

My Method

My method isn't as tidy as Andrew's but it is more stable than Yavin's.

This is just my opinion, you can of course make a game with either of the three and often it will depend on what you are making when you decide how to write something. There is no single best solution for all circumstances.

WARNING: The above comment may contain sarcasm.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 5th Apr 2012 02:23
Very valid points. I suppose I should have clarified, but yes, the structure I used here was fine for this small example but I would indeed structure it slightly differently for a larger project. The framework I use for all my projects is several thousand lines by itself so structure becomes very important. All my code is separated into different files based on functionality groups (i.e. media control, input handling, physics etc.) and all methods within each prefixed suitably (i.e. mediaControl_findFreeObject(), inputHandler_update()) and then all variables for each functionality group declared to match (i.e. inputHandler.current.mouse.click) to almost emulate class-like structure. Its taken quite awhile, but the framework now covers a hell of a lot and means any new project I start I can focus purely on the project specific code. I've always been quite OCD but I really can't stress how much benefit there is from this approach.


Previously TEH_CODERER.

Login to post a reply

Server time is: 2026-07-11 12:00:50
Your offset time is: 2026-07-11 12:00:50