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.

Newcomers DBPro Corner / Play again

Author
Message
Imawizrd
13
Years of Service
User Offline
Joined: 7th Aug 2011
Location:
Posted: 8th Aug 2011 06:31
Hi guys

I'm trying to work out the best way to create a play again function in my game. The function will appear when the player dies and will ask if they want to play the level again, or go back to the main menu.

I was unsure of the best way to "reset the game" when the player goes back to the main menu. Would i delete all the sprites? because i only spawn my sprites when i need them at certain points of gameplay, rather than loading them all at the start and hiding them.

and if i recall all my integers and values would they reset?

e.g

in the game at that point

(integer) x = 10

when i recall it at the start of the game again

x as integer

would that remove its current value?




I hope this post makes sense, let me know if you need anything else for you to assist me. Thanks ^_____^
Imawizrd
13
Years of Service
User Offline
Joined: 7th Aug 2011
Location:
Posted: 8th Aug 2011 06:46
Quote: "and if i recall all my integers and values would they reset?

e.g

in the game at that point

(integer) x = 10

when i recall it at the start of the game again

x as integer

would that remove its current value?"


I just tested this and this and it works.
If i do recall an integer as just "x as integer" it does remove its previous value.
Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 8th Aug 2011 08:32 Edited at: 8th Aug 2011 08:37
The values you will need to reset in a game restart function will vary based upon the game you are playing. There are a number of ways you can do this. What I do is call the restart function from within my main do-loop (repeat - until actually). It goes something like this:



In this example I have previously defined the variable, true, as a constant, which is equal to one. ReGen() is the function that restarts the game.

The ReGen() function in a game I am working on it looks like this:




Please bear in mind that this is just an example to you. Your restart function will likely look very different; it simply is there to give you some of the things that could be included in a game restart function.

Personally, I typically stay away from deleting sprites and creating them all over again. Maybe it is just me, but invariably I am going to delete a sprite that will cause the game to error and I'll spend a lot of time trying to figure out where the problem is.

Variables are integers by default and it is not necessary to declare them as such (unless you want to). You may want to write a function that calls other functions, to initialize particular things. For example, you could have a function to set the player's initial values, another one to setup the background screen, another to reset the items within the game, etc., etc. Example:



When you have multiple sprites / objects etc., it is better to write a function that can install them initially and re-install them later during a restart. In the above example, the SetupBaddies(1) function will initialize all of the enemies, but will not create new sprites. If I was to call SetupBaddies(0), the function will create the sprites for them (this is called when the game is started). This way, the same function can be used to do slightly different things so you don't have multiple sets of code.

Anyway, I hope this is helpful.
Imawizrd
13
Years of Service
User Offline
Joined: 7th Aug 2011
Location:
Posted: 8th Aug 2011 09:23
Hi!

Thanks for the response! In the end i decided to delete sprites when i had finished each scene of my game.

Menu
delete sprites that wont be used in next scene
Level one
delete sprites that wont be used in next scene
Play again? || quit?

Though now i have this problem i can't solve. I'm sure it is something stupid i have done but i just can't find it (maybe im too tired). First time i run my game the sprites are fine, though the second time i run the game they just keep stacking (check the images to see what i mean).

First time playing:


after play again:


This is my main game loop.



It all breaks after PlayAgainMenu
This is the function in that section
Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 8th Aug 2011 17:56
Quote: "(check the images to see what i mean)"

There are no images to look at. You need to upload a pic (use .jpg or .png format).

My guess (and it is a guess) is that it has something to do with either the UpdateSpritePos() function and / or the UpdateSpriteVariables() function. Could you post code for these functions?

Login to post a reply

Server time is: 2024-11-22 18:28:39
Your offset time is: 2024-11-22 18:28:39