Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (606)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java2D painting transparent overlay pause menu  (Read 2557 times)
0 Members and 1 Guest are viewing this topic.
Offline Embedded

Junior Devvie


Medals: 1



« Posted 2012-05-03 11:26:24 »

I'm making a pacman clone and i'm trying to make a pause menu which is just painted on top of the game with transparency to look cool, problem is it paints over and over again making the menu opaque.

To stop this i can continue to paint the normal game underneath the overlay but if i do this it makes things animate as i call player.drawImage(g2d) which then goes and makes the player move onto next animation frame even though the game is paused, so i really don't want to run the drawing code for the normal game at all.

I tried 'screen shoting' the game when i pause it making a copy of the buffer and storing in a buffered image drawing that and then the transparent menu to avoid calling the draw methods for tiles and player but this didn't seem to work very well, i think it was the way i copied the image via bufferedimage.getRaster(), i also tried just doing pauseBuffer = buffer type of copying but this didn't seem to work. Anyone know anyway i can make this work without having to add loads of checks in individual classes draw code to check if the game is paused?
Offline ReBirth
« Reply #1 - Posted 2012-05-03 12:18:15 »

If by just calling draw method results to animation, then you did it wrong. You injected logic part into your draw method.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
private void update(long delta){
  if (!paused){
//continue game logic
  }
}

private void draw(Graphics g){
    //draw everything
    if (paused){
        //draw that menu
    }
}

Offline Embedded

Junior Devvie


Medals: 1



« Reply #2 - Posted 2012-05-03 12:22:33 »

aghh ok, i see. It was only getImage() being called in like the player draw method which went and counted to a next animation frame but i guess i could put it in a update method instead, thanks very much Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-05-03 12:32:18 »

Make that getImage() really throws an image, do nothing more like index increment. Rather, do the increment on update(). You need delta to control the animation don't you?

Offline Embedded

Junior Devvie


Medals: 1



« Reply #4 - Posted 2012-05-03 12:39:02 »

Not using delta as i'm using a fixed time step loop i believe, don't really understand it. Its the only part of this clone i havent written i got it from a tutorial on here i plan to try and understand it one day Tongue

- http://www.java-gaming.org/topics/game-loops/24220/view.html
Offline ReBirth
« Reply #5 - Posted 2012-05-03 12:41:28 »

It's still same. On fixed time step loop you can skip part where you check how much time passed since last update of animation's frame. You still need to separate logic and render. After that, you can try my pseudo-code.

Offline Embedded

Junior Devvie


Medals: 1



« Reply #6 - Posted 2012-05-03 12:47:50 »

okay i'm separating out the logic and rendering code completely into two different methods, should make life easier. I'm using an abstract super class for all my tiles so its an easy thing to add.

Can you link me your pseudo-code? cause it would be nice not to have to write timers everywhere Smiley
Offline ReBirth
« Reply #7 - Posted 2012-05-03 12:57:48 »

Code on my first post is.

Offline Embedded

Junior Devvie


Medals: 1



« Reply #8 - Posted 2012-05-03 13:02:51 »

ohhhh okay i get you, think ill have the paused variable in the class thats calling those methods though e.g.

1  
2  
3  
4  
if(paused){
  player.update();
  map.updateTiles();
}
Offline ReBirth
« Reply #9 - Posted 2012-05-03 13:05:32 »

Yeah. Logic should updates when not paused. But game screen always renders, only the paused menu that makes difference.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (20 views)
2014-12-28 10:39:27

CopyableCougar4 (20 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (58 views)
2014-12-15 09:26:44

Mr.CodeIt (47 views)
2014-12-14 19:50:38

BurntPizza (98 views)
2014-12-09 22:41:13

BurntPizza (116 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!