Jump to content

  • Log In with Google      Sign In   
  • Create Account


splash screen


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 March 2013 - 03:22 PM

I want to add a splash screen to my game but this is new to me, I need a little help. I am making a breakout game using opengl and c++.



Sponsor:

#2 EddieV223   Members   -  Reputation: 1406

Like
2Likes
Like

Posted 16 March 2013 - 03:42 PM

You need game states.  


If this post or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 


#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 March 2013 - 05:02 PM

is this code good for game states

class CGameState
{
public:
  void Init();
  void Cleanup(); void Pause();
  void Resume();

  void HandleEvents();
  void Update();
  void Draw();
};


#4 Damian.   Members   -  Reputation: 272

Like
1Likes
Like

Posted 16 March 2013 - 05:04 PM

It should be OK but, if I'm not wrong you need virtual keyword before void's :-)



#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 March 2013 - 05:09 PM

how do I actually implement this code, I have 14 pages of code, where should I start 

.



#6 Dragonsoulj   Crossbones+   -  Reputation: 2086

Like
2Likes
Like

Posted 16 March 2013 - 05:35 PM

It should be OK but, if I'm not wrong you need virtual keyword before void's :-)

 

You only need virtual if you plan on overwriting the function in child classes. "void" works if you are not returning anything from a function.

 

 

how do I actually implement this code, I have 14 pages of code, where should I start

.

 

I am assuming you already have some game code? Perhaps a running game? Since you want to run the splash before opening any real window (assuming you are using a windowed design), you could just create a splash screen window that does not have any windowed effects (ie title bar, minimize button, close button) to show your splash screen, and while that is displayed, load your resources. When your resources are loaded, call the rest of your already established code, for instance your game window that does have a title bar and a close button.

 

With the structure you posted*, just put the splash screen code in your init() function, at the start, show a splash image, then start loading resources and data. When it finishes, start the game code.

 

* - edited


Edited by Dragonsoulj, 16 March 2013 - 05:35 PM.


#7 EddieV223   Members   -  Reputation: 1406

Like
5Likes
Like

Posted 16 March 2013 - 05:41 PM

It should be OK but, if I'm not wrong you need virtual keyword before void's :-)

 

You only need virtual if you plan on overwriting the function in child classes. "void" works if you are not returning anything from a function.

This is not an accurate way of thinking about it.  First you can overwrite a method in a child class without virtual, however to call it you must have a variable or pointer to the child class.  Virtual is for polymorphism.  If you wish to call a method on a parent class but have the method called for child class of the runtime type.  To get this to work you must use the heap, and there for pointers, and inheritance.


If this post or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 


#8 Dragonsoulj   Crossbones+   -  Reputation: 2086

Like
1Likes
Like

Posted 16 March 2013 - 06:23 PM

 

It should be OK but, if I'm not wrong you need virtual keyword before void's :-)

 

You only need virtual if you plan on overwriting the function in child classes. "void" works if you are not returning anything from a function.

This is not an accurate way of thinking about it.  First you can overwrite a method in a child class without virtual, however to call it you must have a variable or pointer to the child class.  Virtual is for polymorphism.  If you wish to call a method on a parent class but have the method called for child class of the runtime type.  To get this to work you must use the heap, and there for pointers, and inheritance.

 

I was thinking more along the lines of interfaces when Damian. mentioned virtual. You are right.



#9 Dragonsoulj   Crossbones+   -  Reputation: 2086

Like
1Likes
Like

Posted 16 March 2013 - 06:59 PM

assuming you are using a windowed design

 

Forgot to mention:

If you are doing just a full screen game you don't need to create a new window/change styles, just draw the splash screen, handle loading, then clear the screen and start running/drawing your game.



#10 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 March 2013 - 07:02 PM

thanks for all the help, I have a running game, let me work on this problem.



#11 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 17 March 2013 - 03:15 PM

well I am still kind of confused on how to draw a splash screen using opengl



#12 Dragonsoulj   Crossbones+   -  Reputation: 2086

Like
1Likes
Like

Posted 17 March 2013 - 08:54 PM

Open your window, draw a rectangle that fills the window, then apply your splash image as a texture to it. Run your functions that load your game images and data. Start your game loop and start drawing your game.



#13 JTippetts   Moderators   -  Reputation: 8345

Like
3Likes
Like

Posted 17 March 2013 - 09:07 PM

As indicated, you need a way to manage game states. A game state represents a given "phase" of the game's execution: playing the intro video/splash screens for one, displaying and interacting with the opening menu, playing the game. Each of these states includes their own code/data for doing what they do. States typically encapsulate a set of input/update/render operations. (Though some state management can get more difficult than that, it amounts to about the same idea.)

A commonly-used paradigm is that the update routine of a given state, when called, will return a pointer to the state that should be executing next.

Consider the following rough interface for a game state:
class BaseState
{
	public:
	virtual ~BaseState();
	
	BaseState *update(float dt)=0;
	BaseState *handleInput()=0;
	void render()=0;
	bool shouldExit()=0;

};
Any given game state would derive from this interface and implement update, handleInput and render. In the case of intro/splash stuff, the update method would advance the movies, advance timers on the splash screen, or whatever; render would draw the image, and handleInput would listen for Escape or other keys that can be used to early-cancel the splash and dump you to menu. Either of update or handleInput can return a new state. In the case of the splash state, update would return a pointer to a new instance of a MainMenu state as soon as the internal timer runs down to 0 (meaning the splash sequence is ended). handleInput would return a pointer to a new instance of a MainMenu state whenever it indicates that a key press is received to cancel the splash sequence.

Similarly, the MainMenu state would implement its own versions of those three methods. Update wouldn't really do a whole lot, since there isn't much in the way of action going on in a main menu. Update some animations if you have an animated scene for your background. Update some particle effects, whatever. render, of course, would draw the menu. handleInput would listen for mouse clicks, and pass appropriate input to the various UI widgets comprising the main menu and any associated sub-menus or screens. The Start Game menu button (or equivalent) would be attached to a process that would, when clicked and handled in handleInput, construct a new Game state. The Exit Game button would similarly construct an ExitGame state that would shut down all systems and terminate the loop.

And so on.

At the heart of the system is your game loop which operates something like this:
void loop(BaseState *startingstate)
	BaseState *currentstate=startingstate;
	Timer timer;
	
	if(!currentstate) return;
	
	float currenttime=timer.getCurrentTime();
	float elapsedtime=0;
	while(currentstate && !currentstate->shouldExit())
	{
		BaseState *newstate=currentstate->update(elapsedtime);
		if(newstate) currentstate=newstate;
		
		newstate=currentstate->handleInput();
		if(newstate) currentstate=newstate;
		
		currentstate->render();
		
		float nexttime=timer.getCurrentTime();
		elapsedtime=nexttime-currenttime;
		currenttime=nexttime;
	}
}
It's rough, but that's the gist of it. The loop just executes until it's told to stop, and each time through it calls update and handleInput on the current state. If those methods indicate that the state needs to change (a button was pressed, a timer ran out, whatever) then they will return a pointer to the state that should be executing next. Otherwise, they return 0.

After that, it's really just a simple matter of implementing your handleInput, render, update, and shouldExit methods appropriately for the state they represent.

#14 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 17 March 2013 - 09:12 PM

wow that is a lot to digest, I will give it my best shot, that's how I learn.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS