Advertisement
Guest User

asdf

a guest
Jan 7th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package net.devox.basic;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Toolkit;
  8. import java.awt.image.BufferedImage;
  9.  
  10.  
  11.  
  12. /*
  13.  * Title: Game
  14.  * Version: 1.0.0
  15.  * Desc: This class is used to control and pack together the
  16.  *       methods required to run the games logic in a central
  17.  *       location.
  18.  */
  19.  
  20.  
  21.  
  22. public class Game extends Canvas
  23. {
  24.     //buffer for off screen drawing
  25.     private BufferedImage buffer;
  26.    
  27.     private static final long serialVersionUID = 1L;
  28.  
  29.     private void init()
  30.     {
  31.         //turn paint off
  32.         this.setIgnoreRepaint(true);
  33.         //set size
  34.         this.setSize(GUI.WIDTH, GUI.HEIGHT);
  35.         //set Focusable
  36.         this.setFocusable(true);
  37.         //create buffer
  38.         buffer = new BufferedImage(GUI.WIDTH, GUI.HEIGHT, BufferedImage.TYPE_INT_ARGB);
  39.        
  40.        
  41.     }
  42.    
  43.     public void start()
  44.     {
  45.         //initialize game
  46.         this.init();
  47.         //start loop
  48.        
  49.         while(true){
  50.             try{
  51.                 this.update();
  52.                 this.drawbuffer();
  53.                 this.drawscreen();
  54.             }catch(Exception e){e.printStackTrace(); Main.close();}
  55.         }
  56.        
  57.     }
  58.    
  59.     private void update()
  60.     {
  61.         return;
  62.     }
  63.    
  64.     private void drawbuffer()
  65.     {
  66.         //set buffer
  67.         Graphics buff = buffer.createGraphics();
  68.        
  69.         //do drawing logic
  70.         drawrect(buff, 10, 10, 10, 10);
  71.        
  72.         //clear buffer
  73.         buff.dispose();
  74.     }
  75.    
  76.     private void drawscreen()
  77.     {
  78.         Graphics2D g2d = (Graphics2D)getGraphics();
  79.        
  80.         // Render Buffer to Screen
  81.         g2d.drawImage(buffer, 0, 0, this);
  82.        
  83.         Toolkit.getDefaultToolkit().sync();
  84.        
  85.         // Dispose of Graphics2D
  86.         g2d.dispose();
  87.     }
  88.    
  89.    
  90.     //Generic render method. Change this.
  91.     private void drawrect(Graphics buff, int x, int y, int width, int height)
  92.     {
  93.         buff.setColor(Color.BLACK);
  94.         buff.drawRect(x, y, width, height);
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement