Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 10:22 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Fri Jun 24, 2011 4:35 pm 
Offline

Joined: Tue Jun 14, 2011 10:07 pm
Posts: 21
Hey guys,

So I want to create an effect for when my game is paused, hopreully I can clearly describe what I want. So basically I want to have a semi transparent pause screen, through which you can still see the game frozen underneath it. I simply want to have a Resume and Quit option displayed on it.

Is there something built in to slick that can allow me to add this sort of semi transparent layer, or will I have to actually create in photoshop a layer of color with a certain opacity? Its very clear how to create that, I just dont see how I would get game screen to show through.

also, do you guys normally implement paused as another separate GameState, or do you sort of incorporate it as a sub state of the game play state?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2011 6:38 pm 
Offline
Regular

Joined: Tue Jun 19, 2007 7:35 am
Posts: 233
Location: Germany
Simple method:

- Pause-Screen is a separate GameState, so no updates for your Game-Play-State ( it's paused )
- Before switching to the Pause-Screen grab the contents of the Screen aka new Image(width, height) get the graphics and render your scene into the new Image
- Set the grabbed image as a background image for the pause screen and do a fill rect with the desired color and alpha / opacity value
- Draw your other stuff

voila

_________________
Embero Games | Astroiz | ConK | From Outa Space


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2011 6:49 pm 
Offline

Joined: Tue Jun 14, 2011 10:07 pm
Posts: 21
Thanks so much.. That was very clear and makes perfect sense. I considered making the pause screen a separate state entirely, but part of me felt like it should me a mini-state within the gameplay state. But now thinking about it, it does have its own menu so it makes sense to be a state in itself.

Well thanks a lot bud. I will update with how it turns out... and eventually a sample :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 25, 2011 12:26 am 
Offline

Joined: Thu Nov 18, 2010 4:04 pm
Posts: 24
Location: France
Here is an example about how to make a fading pause effect:

Code:
float alpha = 0;

---
In update():
if (gc.getInput().isKeyPressed(Input.KEY_P))
    gc.setPaused(!gc.isPaused());

---
In render():
if (gc.isPaused())
{
    Rectangle rect = new Rectangle (0, 0, windowWidth, windowHeight);
    gr.setColor(new Color (0.2f, 0.2f, 0.2f, alpha));
    gr.fill(rect);

    if (alpha < 0.5f)
        alpha += 0.01f;
}
else
{
    if (alpha > 0)
        alpha -= 0.01f;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2011 4:54 pm 
Offline

Joined: Tue Jun 14, 2011 10:07 pm
Posts: 21
Thanks so much, you guys are the BEST


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2011 5:06 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
hey. If you use StateBasedGame then you dont need to make an image of the gameplay state. Just grab the gameplay state in the pause state and render it, but not update ;)
This way you you dont need to draw to a texture :D

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2011 6:44 pm 
Offline
Regular

Joined: Tue Jun 19, 2007 7:35 am
Posts: 233
Location: Germany
R.D. wrote:
hey. If you use StateBasedGame then you dont need to make an image of the gameplay state. Just grab the gameplay state in the pause state and render it, but not update ;)
This way you you dont need to draw to a texture :D

Sure that's another option. But when i've a pause screen there i don't want a "heavy" gpu load, just as few as possible. Plus you can apply some distortion effect ( blur, and so on ) to that image without much hassle.

There is no right or wrong here, just different kinds of methods. So take whatever is best suited to you and have fun :D

_________________
Embero Games | Astroiz | ConK | From Outa Space


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2011 4:08 am 
Offline

Joined: Tue Jun 14, 2011 10:07 pm
Posts: 21
I dont like starting new topics, so hopefully one of you guys will see this.

So I have an issue that I kind of know how to fix but I feel like there is a MUCH easier way. So I have a paused state and a main menu state. They share similar icons in similar positions on the screen. The problem is this:

Lets say I pause the game, two options appear on the pause screen, RESUME and QUIT. Resume simply goes back to the game and quit goes to the main menu. Heres the problem. The QUIT button on the pause screen and the QUIT button on the main menu (this one actually leave the app) are in the same position. So whats happening is, when I click on the quit game button in the paused screen, it immediately jumps to the main menu, but the main menu gets entered so fast that it registers the mouse as clicking on ITS quit game button. So basically the effect is that pressing QUIT in the pause screen, which should just exit to the main menu, is quitting the entire game, because the mouse click event is still being registered as down when the main menu is entered.

My idea was to add some sort of "clickable" variable on menu items that states whether or not a mouse click is valid, and use some sort of timer that basically enforces that a mouse click should not be registered within a half second or so after the entering of a new state. This seems like it would work, but I feel like theres a better way.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Mar 28, 2012 10:43 am 
Offline
User avatar

Joined: Mon Mar 26, 2012 1:51 am
Posts: 9
TheMatrix154 wrote:
Simple method:

- Pause-Screen is a separate GameState, so no updates for your Game-Play-State ( it's paused )
- Before switching to the Pause-Screen grab the contents of the Screen aka new Image(width, height) get the graphics and render your scene into the new Image
- Set the grabbed image as a background image for the pause screen and do a fill rect with the desired color and alpha / opacity value
- Draw your other stuff

voila


alright,, my question is.. how to pass those ""contents" to the new pause-state (pause-state class) ?


Top
 Profile  
 
PostPosted: Wed Mar 28, 2012 2:16 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
what i've done is to tweak the StateBasedGame class, i've also added some "hooks" for a resume and exit,
(the D is my enumeration class), so if you pause, you keep the last state id in memory and you do a transition to your paused state
if you resume you get the last state back by id and everyting "resumes" automatically without doing noting, the state is paused (not rendered or updated)
until you go back to that state

(if you want i can post you the complete class)
but i changed it quite a lot to my needs because my states are "dynamic"..

cheers

-a-
Code:
  public StateBasedGame(String name) {
        this.title = name;

        currentState = new BasicGameState() {

            public D getID() {
                return D.NULL;
            }

            public void init(GameContainer container, StateBasedGame game) throws SlickException {
            }

            public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
            }

            public void resume() throws SlickException {
            }

            public void pause() throws SlickException {
            }

            public void exit(GameContainer gc, StateBasedGame sbg) {
            }

            public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
            }
        };
    }

....


/**
     * Pause a particular game state with the transitions provided
     *
     * @param pauseId the id of the state to pause
     * @param id      The ID of the state to enter
     * @param leave   The transition to use when leaving the current state
     * @param enter   The transition to use when entering the new state
     */
    public void pauseState(D pauseId, D id, Transition leave, Transition enter) {
        this.pauseId = pauseId;
        enterState(id, leave, enter);
    }

    public void resumeState(Transition leave, Transition enter) {
        enterState(this.pauseId, leave, enter);
    }



Top
 Profile  
 
PostPosted: Wed Mar 28, 2012 3:26 pm 
Offline
User avatar

Joined: Mon Mar 26, 2012 1:51 am
Posts: 9
hmm..
i'm not quit sure if i understand what you have done there..but anyway,, i figured it out already with another technique that is hugely simpler !!!
thanks though for your respond :wink:


Top
 Profile  
 
PostPosted: Wed Mar 28, 2012 4:19 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
:) a solution that can pause any state in the game by keeping the previous id in memory
because i have a game with multiple subgames and i only wanted to have one pause state
so i had to "embed" it into the framework, a complex explenation just to say that i've added
these abstract methods that you can overload in the basic game state

just take a look on the org.newdawn.slick.state.StateBasedGame class (if you use the sources)
and you'll see its quite simple


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], immortal and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group