Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 1851 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 » 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{
      dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);

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:

   //if the buffer wasn't lost, flip the page

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  

hadezbladez (295 views)
2018-11-16 13:46:03

hadezbladez (164 views)
2018-11-16 13:41:33

hadezbladez (295 views)
2018-11-16 13:35:35

hadezbladez (75 views)
2018-11-16 13:32:03

EgonOlsen (2156 views)
2018-06-10 19:43:48

EgonOlsen (2183 views)
2018-06-10 19:43:44

EgonOlsen (1370 views)
2018-06-10 19:43:20

DesertCoockie (1988 views)
2018-05-13 18:23:11

nelsongames (1631 views)
2018-04-24 18:15:36

nelsongames (2279 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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!