Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 2889 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.
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

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.

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.

deepthought (47 views)
2015-06-30 15:39:44

deepthought (50 views)
2015-06-30 15:39:09

deepthought (62 views)
2015-06-30 15:36:52

Za\'Anzabar (36 views)
2015-06-29 05:44:54

TritonDreyja (46 views)
2015-06-24 17:10:40

CopyableCougar4 (46 views)
2015-06-23 00:34:45

BurntPizza (51 views)
2015-06-21 20:36:46

cookiecompiler (93 views)
2015-06-11 15:42:53

cookiecompiler (55 views)
2015-06-11 15:41:14

NegativeZero (79 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

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 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‑
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!