Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  Game Development / Newbie & Debugging Questions / Re: Help! Why so low FPS when i try to draw images on: 2006-01-22 19:53:58
Thank you. The problem had to do with transparency. When i changed to , BufferedImage.TYPE_INT_RGB (instead of ARGB) it runs much smoother. Is it supposed to work like that??


2  Game Development / Newbie & Debugging Questions / Help! Why so low FPS when i try to draw images on: 2006-01-21 05:19:05
Can anyone here explain why i only get 30FPS when i try to draw my map. The problem is this line:

1  
g.drawImage(image[ (map[y][x][0]) ], (x * 32), (y * 32), null);


If i remove it everything runs fine in around 60FPS wich is what i want. Tile.gif is just a normal 16x16 gif file

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;

public class T extends JFrame{
   
   BufferedImage[] image = new BufferedImage[1];
   int[][][] map = new int[100][100][1];
   
   T(boolean full) throws Exception{
      super("Game");
     
      BufferedImage bi = ImageIO.read(new File(System.getProperty("java.class.path") + "/tile.gif"));
      image[0] = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
      image[0].getGraphics().drawImage(
            bi.getSubimage(0, 0, 16, 16), 0, 0, 32, 32, null);
     
      setUndecorated(full);
      setIgnoreRepaint(true);
     
      if(full){
         GraphicsDevice device = getGraphicsConfiguration().getDevice();
         device.setFullScreenWindow(this);
         device.setDisplayMode(new DisplayMode(640, 480, 16, 0));
      }
      else{
         setSize(640, 480);
         show();
      }
     
     
      createBufferStrategy(2);
      BufferStrategy strategy = getBufferStrategy();
     
      int[] colors = {0x00ffff, 0x000000};
     
      int fps = 0;
      long time = System.currentTimeMillis();
      long runTime = System.currentTimeMillis();
      long lastFps = 0;
      int drFps = 0;
      Graphics2D g;
     
      while(System.currentTimeMillis() - runTime < 10000){
         
         long delta = System.currentTimeMillis() - time;
         time = System.currentTimeMillis();
         lastFps += delta;
         fps++;
         
         if(lastFps >= 1000){
            drFps = fps;
            fps = 0;
            lastFps = 0;
         }
         
         g = (Graphics2D)strategy.getDrawGraphics();
         g.setColor(new Color(0x0000ff));
         g.fillRect(0, 0, 640, 480);
         
         int startx  = 0;
         int maxx = startx + (640 / 32) + 1;
         
         int starty = 0;
         int maxy = starty + (480 / 32) + 1;
         
         for(int y = 0; y < maxy; y++){
            for(int x = startx; x < maxx; x++){
               g.drawImage(image[ (map[y][x][0]) ], (x * 32), (y * 32), null);
            }
         }
         g.setColor(new Color(0xffffff));
         g.drawString("FPS: " + drFps, 2, 40);
         g.dispose();
         strategy.show();
         Thread.yield();
      }

      System.exit(0);
     
   }
   
   public static void main(String[] args) throws Exception{
      new T(true);
   }

}
3  Game Development / Newbie & Debugging Questions / Help with collision detection on: 2005-12-21 00:51:41
Hi, i could really use some help with the collison detection for my tile game. There are alot of problem with this algorithm but my mainproblem is when the hero is standing on top off a block i cant get him to fall off. He keeps floating away in the air when he should start falling. I also got trouble figuring out how to move when he jumps and hits the bottom of a block and should start falling back. Any help to optimize this and general tips is very appriciated!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
   public void move(long delta){
     
      if(jumping){
         dy = dy + gravity;
      }
     
      float newx = (dx * delta) / 1000;
      float newy = (dy * delta) / 1000;
     
      Rectangle me = new Rectangle(
            (int)(x + newx),
            (int)(y + newy),
            (int)(getWidth()),
            (int)(getHeight())
      );
     
      Rectangle block = new Rectangle(
            (int)(25*16),
            (int)(29*16),
            (int)16,
            (int)16
      );
     
      if(y + getHeight() > Game.SCREEN_HEIGHT){
         dy = 0;
         newy = 0;
         jumping = false;
         y = Game.SCREEN_HEIGHT - getHeight();
      }
     
     
      if(me.intersects(block)){
         if(newx > 0){
            x = (float)block.getX() - getWidth();
            newx = 0;
         }
         else if(newx < 0){
            x = (float)block.getX() + 16;
            newx = 0;
         }
         if(newy > 0){
            y = (float)block.getY() - getHeight();
            jumping = false;
            newy = 0;
            dy = 0;
           
         }
         else if(newy < 0){
            y = (float)block.getMaxY() + 16;
            newy = -(newy);
         }
      }
     
      x += newx;
      y += newy;
   }
4  Java Game APIs & Engines / Java 2D / Flickering Problems on: 2005-08-27 11:23:10
Hello, im trying to create a simple 2d game but have run into huge problems when i try to draw the graphics.  Every fifth second or so my monitor is flickering badly wich is very annyoing. Here is the source, any help is very appriciated:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import javax.swing.*;

public class Game extends JFrame implements Runnable {
   
   final int SCREEN_WIDTH = 320;
   final int SCREEN_HEIGHT = 240;
   final int BIT_DEPTH = 16;
    final int REFRESH_RATE = 60;
    final int FPS = 60;
   
    float y,x,dx,dy;
    Image img1;
   
    //private InputManager inputManager = new InputManager();
 
   public static void main(String[] args){
      new Game().init(false);
   }
   
   void init(boolean fullscreen){
      setTitle("test");
      GraphicsConfiguration gc = getGraphicsConfiguration();
      GraphicsDevice gd = gc.getDevice();
     
      if(fullscreen) {
         setUndecorated(true);
           gd.setFullScreenWindow(this);
           gd.setDisplayMode(new DisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,BIT_DEPTH, REFRESH_RATE));
        }
     
        else {
           setBounds(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
           setVisible(true);
        }
     
        //remove cursor
           Image cursorImage = Toolkit.getDefaultToolkit().getImage("sprites/transparent.gif");
         Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point( 0, 0), "" );
         setCursor( blankCursor );
         //
       
        setResizable(false);
        setIgnoreRepaint(true);

        //addKeyListener(inputManager);
       
        img1 = loadImage("test.png");
        x = 40; y = 50; dx = 1;

        Thread t = new Thread(this);
        t.start();
   }
   
   public Image loadImage(String filename){
      return new ImageIcon("images/"+filename).getImage();
   }
   
   public void run(){
        final int NANO_FRAME_LENGTH = 1000000000/FPS;
        long startTime = System.nanoTime();
        int frameCount = 0;

        while(true) {
           BufferStrategy bs = getBufferStrategy();
           Graphics2D g = (Graphics2D)bs.getDrawGraphics();
           
           if(x < 0 || x > 320)dx = -dx;
           x += dx;
           //misc rendering
          g.setColor(Color.BLUE);
           g.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
           g.drawImage(img1,Math.round(x),Math.round(y),null);
           bs.show();
           frameCount++;
           // note:System.nanoTime in 1.5+
          while((System.nanoTime()-startTime)/NANO_FRAME_LENGTH <frameCount) {
              Thread.yield();
           }
        }
   }
}
5  Discussions / Community & Volunteer Projects / Re: Console style RPG (like Zelda 3) on: 2005-03-03 15:50:26
Hi, im very interested! I know its been a while since you posted and I ve no idea how active this project still is but i sent you a PM anyway.
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.

BurntPizza (18 views)
2014-09-19 03:14:18

Dwinin (34 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (84 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (64 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (39 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!