Pause - InGame menu - and Save files
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
Pause - InGame menu - and Save files
Is it possible to make a Pause function where it shows a InGame Menu while everything in the background is paused? You know:
-Resume
-Load game
-Save game
-Quit game
-Exit to Windows
And I would also really like to know if it was possible to add Save functions and how its done?
-Resume
-Load game
-Save game
-Quit game
-Exit to Windows
And I would also really like to know if it was possible to add Save functions and how its done?
Chaos vs. Cosmos
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
Of course it'd be possible, it just depends on how you want to handle this.
Back in Xna, I made a game state manager, and split up levels into their own class ( or instance ). From there I would have, I know this is a very odd way of accomplishing this, a variable to check if the game was paused. If so, I stopped everything game wise from updating ( as in player collision, and other game oriented features ), and then show a black transparent image over the game, and after that show a menu. It worked quite well. So I'd suggest looking into game state management. Its probably the best choice to keep everything clean.
Back in Xna, I made a game state manager, and split up levels into their own class ( or instance ). From there I would have, I know this is a very odd way of accomplishing this, a variable to check if the game was paused. If so, I stopped everything game wise from updating ( as in player collision, and other game oriented features ), and then show a black transparent image over the game, and after that show a menu. It worked quite well. So I'd suggest looking into game state management. Its probably the best choice to keep everything clean.
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
You have to handle such states yourself. If you have to pause the game then stop the timer. Then it depends - do you still want to render the background or won't you need that? If you still render it then just put some transparent dialog above it. If you don't need that then put a non-transparent dialog above it and stop calling the sceneManager->drawAll() (it's separate from the guienvironment->drawAll). Same thing with all other things you need to stop/start - just handle it depending on state. For example you might also need to set another camera for the GUI and start onther background music, etc.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
Wont the scripts continue on after i stopped drawing?
Example:
I code two cubes to impact eachother and fall down on the ground. I stop drawing the scene just before the impact.
Bad:
After i unpause the cubes have already impacted although you didnt see it.
Good:
The cubes are still on their way to impact when i unpause.
Also i would also like to know how to make a Save file...
Example:
I code two cubes to impact eachother and fall down on the ground. I stop drawing the scene just before the impact.
Bad:
After i unpause the cubes have already impacted although you didnt see it.
Good:
The cubes are still on their way to impact when i unpause.
Also i would also like to know how to make a Save file...
Chaos vs. Cosmos
Well, that'd be the problem with the scene manager ( pausing it ). Of course, you could stop it from drawing AND stop all your update methods from being called. That way you don't have the game still drawing itself. Although, with that being said, you wouldn't have anything in the backbuffer ( from the scene manager ) as far as I'm aware. Unless Irrlicht maintains that data even when the scene manager isn't drawing. Otherwise, I would just take a snapshot of the screen before the player pauses it, display that, put a transparent image over it ( using the GUI environment I suppose? ) and then render the other GUI. Note that I have not really done much with Irrlicht's GUI system, so I'm not entirely sure how well this will work.
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
Do you have any scripts? You might have animators, but those depend on the timer. So if you stop the timer nothing should get updated anymore. You could probably even continue to render the 3d stuff then as nothing should move anymore.Electricity wrote:Wont the scripts continue on after i stopped drawing?
This stuff depends a lot of the sort of effect you want to have. Many games just continue running in the background (like most shooters for example). Just think for each part of your game if you want to call it's updates or not and whi¢h timer to stop which not. There's no general solution - it has to be decided module by module by yourself.
Do you mean how to write data to files or how to create a menu item? I think menus should be in one of the examples - just checkout those. Saving to files can be done in many ways. In short - think of some file format to use (xml is often practical) - open a file - write the data of your classes in whatever format you like - close the file.Electricity wrote: Also i would also like to know how to make a Save file...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark
Is it possible to stop the timer and drawing for individual scenenodes?CuteAlien wrote:Do you have any scripts? You might have animators, but those depend on the timer. So if you stop the timer nothing should get updated anymore. You could probably even continue to render the 3d stuff then as nothing should move anymore.
This stuff depends a lot of the sort of effect you want to have. Many games just continue running in the background (like most shooters for example). Just think for each part of your game if you want to call it's updates or not and whi¢h timer to stop which not. There's no general solution - it has to be decided module by module by yourself.
No i mean Save files... You know Saveing your game... Loading your game...CuteAlien wrote:Do you mean how to write data to files or how to create a menu item? I think menus should be in one of the examples - just checkout those. Saving to files can be done in many ways. In short - think of some file format to use (xml is often practical) - open a file - write the data of your classes in whatever format you like - close the file.
Chaos vs. Cosmos
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Let's suck it and see.
Stopping the Irrlicht timer stops all animators (including collision response/gravity animators). They will resume from the current position after you start the timer again.
You can (and should) keep calling ISceneManager::drawAll() and IGUIEnvironment::drawAll(). The GUI remains responsive when the timer is paused: note that the buttons change their pressed image even when the timer is stopped.
If you have any of your own behaviour running that you need paused, then you'll just have to avoid running it when the Irrlicht timer is stopped.
Irrlicht provides ISceneManager::saveScene() / ISceneManager::loadScene(), but by default these only save and load the Irrlicht visual entities. However, you can provide your own custom serialiser see (ISceneUserDataSerializer) to add and retrieve user data as the scene is being saved or loaded. This may give you enough functionality to save and load your entire game state. If it doesn't, then you'll have to roll your own saving solution. Either way, you will have to decide what data you need saved and loaded; a game engine can't decide that for you.
It bears repeating that Irrlicht is a very flexible general purpose 3D engine, not a game engine per se.
Stopping the Irrlicht timer stops all animators (including collision response/gravity animators). They will resume from the current position after you start the timer again.
You can (and should) keep calling ISceneManager::drawAll() and IGUIEnvironment::drawAll(). The GUI remains responsive when the timer is paused: note that the buttons change their pressed image even when the timer is stopped.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
enum
{
Button_Pause = 101,
Button_Start
};
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(IrrlichtDevice * device) : Device(device) { }
virtual bool OnEvent(const SEvent& event)
{
if (EET_GUI_EVENT == event.EventType &&
EGET_BUTTON_CLICKED == event.GUIEvent.EventType)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = Device->getGUIEnvironment();
ITimer * timer = Device->getTimer();
switch(id)
{
case Button_Pause:
if(!timer->isStopped())
timer->stop();
return true;
case Button_Start:
if(timer->isStopped())
timer->start();
return true;
default:
break;
}
}
return false;
}
private:
IrrlichtDevice * Device;
};
int main()
{
IrrlichtDevice * device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
MyEventReceiver receiver(device);
device->setEventReceiver(&receiver);
IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
ISceneManager * smgr = device->getSceneManager();
env->addButton(rect<s32>(10,10,110,10 + 32), 0, Button_Pause, L"Pause", L"Pauses animation");
env->addButton(rect<s32>(10,50,110,50 + 32), 0, Button_Start, L"Start", L"Starts animation");
(void)smgr->addCameraSceneNode(0, vector3df(0, 0, -60));
IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZBUFFER, false);
ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(vector3df(0, 0, 0), 40, .01f, vector3df(0, 0, -1));
bill->addAnimator(animator);
animator->drop(); animator = 0;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
env->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Yes, we understand you, but the solution is entirely dependent on your game and what data you want to save.Electricity wrote:No i mean Save files... You know Saveing your game... Loading your game...CuteAlien wrote:Do you mean how to write data to files or how to create a menu item? I think menus should be in one of the examples - just checkout those. Saving to files can be done in many ways. In short - think of some file format to use (xml is often practical) - open a file - write the data of your classes in whatever format you like - close the file.
Irrlicht provides ISceneManager::saveScene() / ISceneManager::loadScene(), but by default these only save and load the Irrlicht visual entities. However, you can provide your own custom serialiser see (ISceneUserDataSerializer) to add and retrieve user data as the scene is being saved or loaded. This may give you enough functionality to save and load your entire game state. If it doesn't, then you'll have to roll your own saving solution. Either way, you will have to decide what data you need saved and loaded; a game engine can't decide that for you.
It bears repeating that Irrlicht is a very flexible general purpose 3D engine, not a game engine per se.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 28
- Joined: Sun Aug 03, 2008 10:10 am
- Location: Denmark