Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  FSEM headaches!  (Read 906 times)
0 Members and 1 Guest are viewing this topic.
Offline TLE

Senior Newbie





« Posted 2007-01-13 22:59:03 »

Ok, I've just started playing around with game animation type stuff.  I figured out a lot with applets, using threads and double buffering backgrounds and animating pictures.  Now I'm trying to learn the same stuff but with full screen (I don't like the applet windows :\)

So I'm using JFrame to write an FSEM application.  I'm having trouble figuring out how to do this.  Naturally, I wanna use a thread like I did with the applet, but threads require runnable -- should I have my FSEM implement runnable?  Or will this make it less effecient/harm it in some way?

Also, for getting images from files, I was using getImage(getCodeBase(), "imagename.extension"), but this only works with applets.  How do I do this without an applet? 

Any help or pointers is appreciated!
Offline SluX

Junior Devvie





« Reply #1 - Posted 2007-01-14 12:31:14 »

http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html Check out this tutorial.

As far as for image loading, use ImageIO.

Good luck.

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline TLE

Senior Newbie





« Reply #2 - Posted 2007-01-14 17:05:44 »

I really don't like that tutorial :\
I understand what it's talking about when I read it, but I can't figure out how to piece things together with actual code from it, and when I look at the example codes provided there, I can't follow any of it.

Any way, I've made some progress, got things to show up and such, but now I'm having a problem with my double buffering maybe?  Basically, I have a picture showing up on a blue screen and it changes every x frames (for animation).  However, it's blinking every time it re-draws the scene, any idea what I have wrong here?

public void render() throws java.io.IOException{
       if(dbImage==null){
         dbImage=createImage(this.getSize().width,this.getSize().height);
         dbg=dbImage.getGraphics();
      }
      
      dbg.setColor(getBackground());
      dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
      dbg.drawImage(image,x,y,this);
      
      displayImage(0,0,dbImage);
}

public void displayImage(int a, int b, Image i) {
       Graphics g = getBufferStrategy().getDrawGraphics();
       try {if(g!=null && i!=null)g.drawImage(i, a, b, null);}
       finally {g.dispose();}
    }
   
    public void displayImage(Image i) {displayImage(x,y,i);}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie





« Reply #3 - Posted 2007-01-15 16:20:03 »

Yes, it's probably a problem with your double buffering.  You need to add the following code after disposing the Graphics object:

1  
2  
3  
   //if the buffer wasn't lost, flip the page
   if(!bufferStrategy.contentsLost())
      bufferStrategy.show();


The show method flips the buffer.  When you create the BufferStrategy with the createBufferStrategy method, make sure you call it with an argument of 2.  That makes it so that it's double buffered.  1 buffer would just be the regular screen buffer.  2 buffers gives you the regular screen buffer plus 1 that you can switch with.  When you draw to the Graphics object, you're drawing to the off-screen buffer.  The show method waits for the vertical retrace and then swaps the two buffers, causing whatever you drew to be displayed without flicker.

You don't need to do your own double buffering by creating dbImage.  You can just draw straight to the Graphics object from the BufferStrategy.  The only reason I would ever have something like dbImage is if I had to do some kind of image effect to the screen before I displayed it.  You would still need the double buffer then because Java gives you no way to wait for the vertical retrace yourself.
Offline TLE

Senior Newbie





« Reply #4 - Posted 2007-01-16 01:15:02 »

Yep, those were my problems exactly, thanks a bunch!

Oh and your explanation was KILLER!  Understand buffer strategy a shitload better now!  (compared to almost not at all though, haha)
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.

toopeicgaming1999 (50 views)
2014-11-26 15:22:04

toopeicgaming1999 (43 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (25 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!