Advertisement

problems with object selection

Started by April 28, 2005 08:24 AM
0 comments, last by eSCHEn 19 years, 7 months ago
i have a game menu where if you click on a planet it brings you into the main game, there is a global variable that changes if you click on the planet: //you are in main game menu at the moment if(startGame==1)//check if you clicked on this object { RenderScene2();//render the level CheckForMovement(); rollTop-=.009f; rollBack-=.003f; rollGround-=.009f; } so if you click on the planet, it immediately goes into the game level , ie from RenderScene() to RenderScene2(), the problem is that i have a crosshair in my level and if you click on a certain part of the screen it brings you into another renderscene method, (i have 4 methods, game menu, main level, high scores and multiplayer, i know whats going on, basically the 2 renderscenes are still running together and its causing havoc with my game, is there any way i can kill the previous renderscene method before going into my new one???
go hard or go home :)
The way I do it is using a pair of function pointers, like this:
// setupvoid (*RenderFunc) ();void (*UpdateFunc) ();// you need a render and update function for each statevoid MenuRender(){  // render menu stuff}void MenuUpdate(){  // update menu stuff}void GameRender(){  // render game stuff}void GameUpdate(){  // update game stuff} // set to menu initiallyRenderFunc = MenuRender;UpdateFunc = MenuUpdate;// in your hit testif (hitplanet){  RenderFunc = GameRender;  UpdateFunc = GameUpdate;}// in your message pumpUpdateFunc();RenderFunc();

So what happen is the function pointer is called every time in the message pump, it points to whatever function it has been set to and therefore that function is called.
You can add as many states as you like, for example you might want a 'GameUnload' pair of functions which unload all of the textures etc. for a game before it hands control back to the menu.

One thing to note is that function pointers are very easy to understand but can be tricky to get the syntax right, this site helped me out on more than one occasion.

Hope that helped :)
--
Cheers,
Darren Clark

This topic is closed to new replies.

Advertisement