Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (467)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: Avoidance of Garbage Collection on: 2005-03-01 19:10:17
Yeah, I went to useing a Graphics gotten from the BufferStrategy to render the image, I was a little dissapointed that they did not have the option to draw a single pixel, I decided to just use a fillRect(x, y, 1, 1); Worked at a good speed even at high resolutions like 1600 x 1200.  Although now that I am useing sprites, I am having trouble becasue it seems to take a really long time to draw a buffered image to a Graphics.  Is there any way to move the image into the memory on the graphics card so that it can access it quickly?
2  Java Game APIs & Engines / Java 2D / Re: Avoidance of Garbage Collection on: 2005-02-28 03:58:44
Another thing I was wondering was weather the use of something like a blocking queue to manage FPS is a good idea.

[CODE]
int fps = 30;

LinkedBlockingQueue<Thread> bq = new LinkedBlockingQueue<Thread>(1);

while(!exit)
{
   bq.put(new Thread(updater));
   bq.peek().start();
   Thread.sleep(1000/fps);
}
[/CODE]

Then have the updater somehow remove it'self from the LinkedBlockingQueue.  It prevents more than one updater from running at the same time, but also makes the wait continue while the thread is running.
3  Java Game APIs & Engines / Java 2D / Avoidance of Garbage Collection on: 2005-02-28 03:44:26
Is it a good idea to avoid creating a new BufferedImage every time an image is refreshed to avoid java garbage collection, and if so, is it a good idea to have a blank image or blank raster to reset the image to when you want to redraw it?  Is there a better way?  What I have is this.

[CODE]
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
/**
* @author Scott
*
*/
public class ScreenManager
{
   private BufferedImage bi;
   private Raster blank;
   
   private BufferStrategy bs;
   
   private int width;
   private int height;
   
   public ScreenManager(int width, int height)
   {
       JFrame screenFrame = new JFrame(String.format("%dx%d", width, height));
       screenFrame.setSize(width+6, height+24);
       screenFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       screenFrame.setResizable(false);
       screenFrame.setVisible(true);
       
       this.width = width;
       this.height = height;
       
       screenFrame.createBufferStrategy(2);
       
       bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
       blank = bi.getData();
       
       bs = screenFrame.getBufferStrategy();
       
   }
   
   public void drawPixel(int x, int y, Color c)
   {
       bi.setData(blank);
       //bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
       bi.setRGB(x,y,c.getRGB());
   }
   
   public void refresh()
   {
       render(bs.getDrawGraphics(), bi);
       bs.show();
   }
   
   public void render(Graphics g, Image i)
   {
       
       g.drawImage(i, 3, 21, null);
   }
}
[/CODE]

and

[CODE]
import java.awt.*;

/**
* @author Scott
*
*/
public class Main
{
   private int pixelX;
   private int pixelY;
   
   public static void main(String[] args)
   {
       ScreenManager sm = new ScreenManager(320, 240);
       
       for(int i = 0;i < 320; i++)
       {
           if(i == 319) i = 0;
           for(int j = 0;j < 240;j++)
           {
               if(j == 240) j = 0;
               sm.drawPixel(i, j, Color.WHITE);
               sm.refresh();
           }
       }
       
       sm.refresh();
   }
}
[/CODE]
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (81 views)
2014-04-15 18:08:23

BurntPizza (73 views)
2014-04-15 03:46:01

UprightPath (84 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (84 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (214 views)
2014-04-04 12:06:45

CJLetsGame (223 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!