Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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] 2
1  Games Center / Featured Games / Re: Revenge of the Titans on: 2010-12-24 06:39:26
I have to say this game looks totally awesome, love the art too!
2  Game Development / Newbie & Debugging Questions / Re: profiling on: 2010-06-24 04:28:25
As a guess I'd say your output is listing the methods called in each running thread, the number of times it was called and the percentage of total CPU that they each used. But that is just a guess.

As an alternative I'd recommend taking a look at JVisualVM. It'll be a lot easier then profiling via the command line. Goto the bin folder of your JDK (approximately: C:/program files/java/jdk1.6.0_17/bin) and you should see 'jvisualvm.exe'. Run it and wait for it to open. Then run your game/app and it'll appear listed on the left. You then double click on it to get JVisualVM to connect.

Once it's connected you can see the memory and GC usage as well as setting it up to profile your app in greater detail.

Ok thanks, I'll try it out now!

Edit: I have to to say this thing looks pretty cool, I'll get back to you once I understand how to read the charts in it, for some reason the "Memory" in the profiler is taking ages to load(still not loaded) but other things look good. Thanks again for the help =)


3  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-22 15:57:29
I think I got rid of flickering, can someone please be kind enough to check if you still get flickering when scrolling from my game? For some reason making it full screen seems to do the trick....I have no idea why...

Link to code, the zip file contains 3 jars, just different way of doing things:
http://www.mediafire.com/?mndtjmninzt

Here's the code highlight for each jar, note that my screen has a resolution of 1024 * 768, scrolling is done by moving mouse to left/right edge of the screen:

- Sof_FS.jar  is the first full screen method I tried
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  
  GraphicsDevice gd;

        GraphicsEnvironment ge =
              GraphicsEnvironment.getLocalGraphicsEnvironment();
          gd = ge.getDefaultScreenDevice();
          GraphicsConfiguration gc = gd.getDefaultConfiguration();

         final int currentRefreshrate = gd.getDisplayMode().getRefreshRate();
         
         System.out.println("Reported Refreshrate=" + currentRefreshrate);
         targetFps = (currentRefreshrate==DisplayMode.REFRESH_RATE_UNKNOWN?60:currentRefreshrate);
           
      Frame frame = new Frame(gc);
      frame.setIgnoreRepaint(true);
      frame.setUndecorated( true );
      frame.setLayout(null);
      setIgnoreRepaint(true);
      setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.add(this);
      frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.setFocusTraversalKeysEnabled(false);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
     
       // Change to full screen
      gd.setFullScreenWindow(frame);
       if( gd.isDisplayChangeSupported() ) {
         gd.setDisplayMode(
           new DisplayMode( WINDOWS_WIDTH, WINDOWS_HEIGHT, 32, DisplayMode.REFRESH_RATE_UNKNOWN )
         );
       }


- Sof_FS2.jar  is the second full screen method I tried:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
                Frame frame = new Frame("Test Scroller");
      frame.setLayout(null);
      setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.add(this);
      frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
     
//      Exit windows
     frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
     
      /** create the strategy used for accelerated rendering. */
      createBufferStrategy(2);
      strategy = getBufferStrategy();

            //I simply added these 2 lines to the original code
      GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().setFullScreenWindow(frame);


- SoF.jar, the non-full screen mode:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
Frame frame = new Frame("Side Scroller");
      frame.setLayout(null);
      setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.add(this);
      frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
     
//      Exit windows
     frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
     
      /** create the strategy used for accelerated rendering. */
      createBufferStrategy(2);
      strategy = getBufferStrategy();


4  Game Development / Newbie & Debugging Questions / profiling on: 2010-06-22 08:18:45
Dear JGO Members,

I've read the guide in the java2D section about profiling, I've tried passing the variables as argument in Eclipse but still can't get it to work. Sorry that I'm pretty new to profiling it would be really nice if someone can shade me some light on how profiling works. Thanks in advance!


Edit: After abit more search I found out -Xpro can do profiling, did it on CMD, but I'm not sure exactly what those mean, like what's good it terms of performance and whats bad?
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  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
C:\>java -jar -Xprof GGt.jar

Flat profile of 34.68 secs (3128 total ticks): AWT-Windows

  Interpreted + native   Method
 99.7%     0  +  3119    sun.awt.windows.WToolkit.eventLoop
  0.1%     2  +     0    sun.awt.AWTAutoShutdown.setToolkitBusy
  0.0%     1  +     0    sun.reflect.NativeMethodAccessorImpl.invoke
  0.0%     1  +     0    sun.awt.SunToolkit.wakeupEventQueue
  0.0%     0  +     1    java.lang.Object.hashCode
  0.0%     0  +     1    sun.awt.windows.WToolkit.init
 99.9%     4  +  3121    Total interpreted

     Compiled + native   Method
  0.1%     0  +     3    sun.awt.AWTAutoShutdown.setToolkitBusy
  0.1%     0  +     3    Total compiled


Flat profile of 0.11 secs (7 total ticks): Thread-1

  Interpreted + native   Method
100.0%     0  +     7    sun.awt.windows.WToolkit.shutdown
100.0%     0  +     7    Total interpreted


Flat profile of 34.70 secs (3127 total ticks): AWT-EventQueue-0

  Interpreted + native   Method
 31.0%     0  +    26    sun.awt.windows.WFramePeer.setState
 23.8%     0  +    20    sun.awt.windows.WGlobalCursorManager.setCursor
 13.1%     0  +    11    sun.awt.windows.WGlobalCursorManager.findHeavyweightUnd
erCursor
  9.5%     0  +     8    sun.awt.windows.WComponentPeer.nativeHandleEvent
  8.3%     1  +     6    sun.awt.Win32GraphicsDevice.enumDisplayModes
  1.2%     0  +     1    java.lang.Thread.holdsLock
  1.2%     0  +     1    java.lang.Object.clone
  1.2%     0  +     1    java.lang.Class.getInterfaces
  1.2%     0  +     1    sun.awt.windows.WComponentPeer.reshape
  1.2%     0  +     1    sun.java2d.loops.FillRect.FillRect
  1.2%     0  +     1    sun.java2d.windows.GDIBlitLoops.nativeBlit
  1.2%     1  +     0    java.awt.DisplayMode.<init>
  1.2%     1  +     0    sun.awt.AWTAutoShutdown.notifyThreadBusy
  1.2%     1  +     0    java.awt.Window.processWindowEvent
  1.2%     1  +     0    java.awt.EventQueue.setCurrentEventAndMostRecentTimeImp
l
 97.6%     5  +    77    Total interpreted

     Compiled + native   Method
  1.2%     1  +     0    sun.awt.AppContext.get
  1.2%     1  +     0    Total compiled

         Stub + native   Method
  1.2%     0  +     1    java.lang.Thread.currentThread
  1.2%     0  +     1    Total stub

  Thread-local ticks:
 97.3%  3043             Blocked (of total)


Flat profile of 34.78 secs (3134 total ticks): AWT-Shutdown

  Thread-local ticks:
100.0%  3134             Blocked (of total)


Flat profile of 34.80 secs (3136 total ticks): Java2D Disposer

  Thread-local ticks:
100.0%  3136             Blocked (of total)


Flat profile of 34.88 secs (3142 total ticks): main

  Interpreted + native   Method
  2.9%     0  +    92    sun.nio.ch.FileDispatcher.read0
  1.9%     0  +    61    sun.java2d.windows.GDIBlitLoops.nativeBlit
  1.1%     0  +    36    sun.java2d.loops.Blit.Blit
  0.4%     0  +    14    sun.java2d.loops.FillRect.FillRect
  0.4%     0  +    13    java.io.RandomAccessFile.close0
  0.2%     0  +     5    java.io.RandomAccessFile.open
  0.2%     5  +     0    java.awt.image.DataBufferByte.<init>
  0.2%     0  +     5    java.util.zip.Inflater.inflateBytes
  0.1%     0  +     4    sun.font.FontManager.populateFontFileNameMap
  0.1%     0  +     3    sun.font.FileFont.getGlyphImage
  0.1%     3  +     0    java.lang.AbstractStringBuilder.<init>
  0.1%     0  +     3    sun.java2d.loops.DrawGlyphList.DrawGlyphList
  0.1%     0  +     2    java.lang.Throwable.fillInStackTrace
  0.1%     1  +     1    sun.java2d.loops.MaskBlit.MaskBlit
  0.1%     2  +     0    java.awt.image.DataBufferInt.<init>
  0.1%     2  +     0    com.sun.imageio.plugins.png.PNGImageReader.decodePaethF
ilter
  0.0%     1  +     0    sun.font.TrueTypeFont.close
  0.0%     0  +     1    sun.awt.windows.WWindowPeer.reshapeFrame
  0.0%     1  +     0    sun.java2d.SunGraphics2D.drawImage
  0.0%     1  +     0    sun.net.www.protocol.file.Handler.createFileURLConnecti
on
  0.0%     0  +     1    java.io.RandomAccessFile.seek
  0.0%     0  +     1    sun.awt.Win32GraphicsDevice.enterFullScreenExclusive
  0.0%     0  +     1    java.lang.reflect.Array.newArray
  0.0%     0  +     1    java.io.WinNTFileSystem.list
  0.0%     1  +     0    java.awt.Rectangle.setBounds
  9.4%    43  +   251    Total interpreted (including elided)

     Compiled + native   Method
 50.7%  1591  +     0    java.awt.image.ComponentColorModel.getRGBComponent
 16.8%   529  +     0    java.awt.image.ComponentColorModel.getRGB
 15.4%   485  +     0    sun.awt.image.ByteInterleavedRaster.getDataElements
  3.5%   110  +     0    sun.java2d.loops.OpaqueCopyAnyToArgb.Blit
  1.0%    30  +     0    com.sun.imageio.plugins.png.PNGImageReader.decodePaethF
ilter
  0.2%     7  +     0    com.sun.imageio.plugins.png.PNGImageReader.decodeUpFilt
er
  0.0%     1  +     0    java.io.BufferedInputStream.read
  0.0%     1  +     0    com.sun.imageio.plugins.png.PNGImageReader.decodePass
  0.0%     1  +     0    Map.Map.paint
 87.7%  2755  +     0    Total compiled

         Stub + native   Method
  2.2%     0  +    69    sun.java2d.loops.MaskBlit.MaskBlit
  0.4%     0  +    12    java.util.zip.Inflater.inflateBytes
  0.2%     0  +     7    java.lang.System.arraycopy
  0.1%     0  +     2    java.lang.Thread.currentThread
  0.0%     0  +     1    java.io.RandomAccessFile.readBytes
  2.9%     0  +    91    Total stub

  Thread-local ticks:
  0.0%     1             Blocked (of total)
  0.0%     1             Class loader


Global summary of 34.88 seconds:
100.0%  3163             Received ticks
  0.7%    21             Received GC ticks
  0.2%     7             Compilation
  0.0%     1             Class loader

5  Game Development / Newbie & Debugging Questions / Re: Sprite Alpha on: 2010-06-22 04:06:27
If your doing what I'm thinking you are doing then you can try this, this allows you to change the transparency on an image, preferably a png:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
        /** Image transperancy value*/
   float transperancy = 0;

   public BufferedImage drawAlpha() {
      /** Load Image, note that it is better if you preload the image else where, this is just to show you how its loaded. */
      BufferedImage loaded = ImageIO.read(new File("images/buildings/g_u_1.png"));

      /** Create alpha image */
      BufferedImage aimg = new BufferedImage(loaded.getWidth(), loaded.getHeight(), BufferedImage.TRANSLUCENT);  

       /** Get image graphics */
      Graphics2D g = aimg.createGraphics();

      /** Set the Graphics composite to Alpha */
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transperancy));  

      /** Draw the loaded image into the prepared reciver image */
      g.drawImage(loaded, null, 0, 0);  

      /** Release system resource in this graphics */
      g.dispose();
     
      return aimg;
   }


And this is how you would draw it, the transparent value has a range from 1.0 ~ 0.0, hope it helps.:
1  
2  
3  
public void paint(Graphics2D g) { 
      g.drawImage(drawAlpha(), x, y, width, height, null);
}
6  Game Development / Newbie & Debugging Questions / Re: hello, two questions: how to vsync? and how to fullscreen? using graphics2D on: 2010-06-21 06:36:34
That's interesting, I've always thought getting a full screen java application is alot harder than...2 lines of code XD.

I just tried it, it looks beautiful! Thanks for the code =)
7  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-21 06:34:50
im trying something similar and I think what we need is a way to do vsync, I asked for that in other post, I hope someone give an answer.  Cool

Does vsync get rid of flickering? I'm using double buffering and I still get flickering. It would be really nice if someone can show me how to do scrolling properly, perhaps my way of doing it is just wrong. The way I scroll is to have screen follow this "camera(an invisible rectangle) and when I move mouse to the left/right edges of the screen it increments/decrements the X position of the camera and as an end result the map scrolls.

I noticed in my games when ever I scroll right my character "shifts back" a little bit when he's near the edge, perhaps this will lead to the root cause of my weird flickering bug.


Edit: I tried it, still doesn't get rid of flickering and I'm not sure whats wrong with my scrolling code.

Here's how I do scrolling in case anyone's interested:
I have 2 variables to tell where the camera is at now, lets forget about Y for now since I'm only doing horizontal scrolling. VisibleX is declared as    public static int visibleX = GameCore.WINDOWS_WIDTH / (8 * Map.TILE_SIZE);

Where WINDOWS_WIDTH is 1024(my screen width);
 and camera.x is camera's current position.

Cornershift is just to shift edges according to player's position so that things outside of the actual map won't be seen.

1  
2  
3  
mapPosX = Camera.visibleX - Camera.x;
mapPosY = Camera.visibleY - Camera.y;
cornerShift();


Then this is how I calculate the offset to be used for all scrolling

1  
2  
3  
4  
5  
6  
7  
8  
/** Offset X for Camera */
int offsetX = (int)((GameCore.mapPosX + GameCore.fixX)* Map.TILE_SIZE);

/** Offset Y for Camera */
int offsetY = (int)((GameCore.mapPosY + GameCore.fixY) * Map.TILE_SIZE);

// Somewhere in paint method I draw the rectangle with the offset
g.drawRect(xp + offsetX, yp + offsetY, width, height);



I've tried all sorts of game loop today, tried running the game in full screen/windowed application as well and different methods posted on forum to get rid of flickering. I can't really find any bugs/flaws in my scrolling method and none of the methods I tried work so far, any help would be greatly appreciated.
8  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-19 08:26:45
EDIT: I found the problem, it has nothing to do with the game loop at all, there's something wrong with my scrolling offset, I'll try and fix it now. Thanks for the help!

I tried the method adon_y_coya suggested but the flickering is still there =/. I'm just curious, what are the possible causes that could cause flickering in java?

Here's the code for my frame:

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  
Frame frame = new Frame("Stone of Franks");
      Panel panel = new Panel();
      panel.setLayout(null);
     
      Canvas canvas = new Canvas();
      canvas.setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      canvas.setIgnoreRepaint(true);
     
      panel.add(canvas);
      frame.add(panel);

      frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
     
      /** create the strategy used for accelerated rendering. */
      canvas.createBufferStrategy(2);
      strategy = canvas.getBufferStrategy();
     
      canvas.requestFocus();
     
      //Exit windows
     frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });


         /** Add Key Listener */
      canvas.addKeyListener(this);
     
      /** Add Mouse Listener */
      canvas.addMouseListener(this);
      canvas.addMouseMotionListener(this);

9  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-18 11:24:55
Put a panel in your frame (and set layout null) then put a canvas in that panel and setIgnoreRepaint(true) and have the canvas createBufferStrategy(2) and then request focus.
That solved all flickering issues I've had.

Thanks for the reply! I'll try that when I get home. I'm not using any swing components tho will that be fine?
10  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-17 10:00:10
double posted by accident..
11  Game Development / Newbie & Debugging Questions / Re: Scrolling 2D Image problem on: 2010-06-17 09:41:21
Hey Riven,


Thanks for the fast reply, this is what the gameRender() looks like, sorry but what is EDT?

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  
   GameCore() {
      Frame frame = new Frame("Side Scroller");
      frame.setLayout(null);
      setBounds(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.add(this);
      frame.setSize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
      frame.setResizable(false);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      frame.addKeyListener(this);
      addKeyListener(this);
      //Exit windows
     frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
     

      /** create the strategy used for accelerated rendering. */
      createBufferStrategy(2);
      strategy = getBufferStrategy();

                 //Other code here
       
      setFPS();
      gameLoop();
   }


private void gameRender() {
      Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
     
      // clear the screen
     g.setColor(Color.WHITE);
      g.fillRect(0,0,WINDOWS_WIDTH,WINDOWS_HEIGHT);
      g.translate(0, 10);

      if(player.isAlive() && gameStart) {
         /** Paint map */
         map.paint(g);
         
         /** Paint enemies */
         spawn.paint(g);
         
         /** Pain Power Ups */
         powerUp.paint(g);
         
         /** Paint player */
         player.paint(g);
         
         /** Paint GUI */
         gui.paint(g);
      }

      /** Paint Scene */
      scene.paint(g);
     
      /** flip the buffer so we can see the rendering */
      g.dispose();
      strategy.show();
   }



Edit: I'm trying to keep the game single threaded to keep it as simple as possible. I'm not very good with multi-threading yet.

Edit 2: The silhouette only happens on the g.fillRect() Rectangles, the images don't have that effect and it only happens when I'm scrolling.

Edit 3: The paint(g) code is something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   /** Draw Player */
   public void paint(Graphics2D g) {
      /** Paint spells */
      for(int i = spellList.size() - 1; i >= 0 ; i--) {
            spellList.get(i).paint(g);
      }
         
      /** Paint explosions */
      for(int i = explosion.size() - 1; i >= 0; i--) {
         if(explosion.get(i).Length() != 0) {
            explosion.get(i).paint(g);
         }
      }

      g.drawImage(anim.getCurrentImage(), xp + offsetX - 10, yp + offsetY, null);
   }

12  Game Development / Newbie & Debugging Questions / Scrolling 2D Image problem on: 2010-06-17 09:29:46
Dear JGO Members,


I'm having this weird problem when doing side scrolling at a fast speed, the rectangles drew with g.fillRec() start to have some sort of silhouette and images flashes, I have tried to use variable framerate game loop or increase fps in the fixed framerate loop but neither works. The following is an attempt to demonstrate the problem:

Flashing when moving 1
http://www.youtube.com/watch?v=aS6LF9GNkjM
Flashing when moving 2
http://www.youtube.com/watch?v=aS6LF9GNkjM

Picture to show where the silhouette is when scrolling:


Uploaded with ImageShack.us

I'm not exactly sure what the cause of the problem is since it looks fine if I scroll at slower speed, I'm guess the problem has to do with the game loop I'm using, note that I want to have a fixed framerate game loop. Below is the code of the loop, thanks in advance!

The loop is taken from here:
Fixed Framerate loop
http://wiki.games4j.com/wiki/en/Timing_in_main_loops

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  
        private int fps;
   private long timeThen;

   /** Set FPS */
   private void setFPS() {
      fps = 60;
      timeThen = System.nanoTime();
   }

        /** Timer */
   public void sync() {
      long gapTo = 1000000000L / fps + timeThen;
      long timeNow = System.nanoTime();
     
      while (gapTo > timeNow) {
         try { Thread.sleep(1);
         } catch (InterruptedException e) {}
         timeNow = System.nanoTime();
      }
      timeThen = timeNow;
   }


       /** Fixed Framerate Game loop */
   private void gameLoop() {
      long currentUpdateTime = System.nanoTime();
      long lastUpdateTime;  
         
      while(gameRunning) {
         
         lastUpdateTime = currentUpdateTime;
         currentUpdateTime = System.nanoTime();
         long elapsedTime = (currentUpdateTime -    lastUpdateTime)/(1000*1000);
         
         /** Update Game */
         gameUpdate(elapsedTime);
         /** Render */
         gameRender();
         /** Run timer */
         sync();
      }
   }


13  Game Development / Game Mechanics / Re: Particle Explosion on: 2010-04-21 14:31:14
Here is some of my code for dealing with particles:
http://code.google.com/p/skorpios/source/browse/trunk/skorpios-common/src/com/esotericsoftware/skorpios/opengl/particles/Particles.java

The project also has an editor tool:
http://code.google.com/p/skorpios/source/browse/trunk/skorpios-desktop/tools/com/esotericsoftware/skorpios/tools/particles/ParticleEditor.java

Editor screenshot:


Basically you give each particle an angle (randomly distributed between 0 and 360 degrees to emit in all directions), and also a velocity (pixels per second is an easy unit). Then each update you change the position of the particle this way:

1  
2  
x += velocity * Math.cos(angle);
y += velocity * Math.sin(angle);


Note that Math.cos/sin takes an angle in radians.

Be sure to take into account the number of milliseconds that have passed since the last update when applying your velocity.

You may want to store precomputed values for velocityX and velocityY. I do the sin/cos each update because I allow my particles' angle to change during its life.

That formula there did the trick, thanks alot!
14  Game Development / Game Mechanics / Re: Particle Explosion on: 2010-04-21 14:00:08
Cool, thanks for that link, I"ll take a look now XD
15  Game Development / Game Mechanics / Re: Particle Explosion on: 2010-04-21 06:43:22
Wow that's pretty impressive stuff there...I'll definitly dive deeper into the code once I get off work, thanks!
16  Game Development / Game Mechanics / Particle Explosion on: 2010-04-21 04:08:52
Hi, I'm not sure if this is the right section for this kind of stuff, but I'll post here anyway. I have an explosion class that draws lots of particles moving in random direction and forms a square explosion shape, I'm just wondering if there is a formula or algorithm I can use to create a circular explosion shape. Thanks in advance!
17  Game Development / Newbie & Debugging Questions / Re: Load large background image on: 2010-03-27 16:03:08
I've made my background image smaller (1600 * 765) and it is making things alot better, I guess I'll have to load a couple smaller image this size and connect them through code to speed up performance, the parallel scrolling is working good and thanks for the help!
18  Game Development / Newbie & Debugging Questions / Re: Load large background image on: 2010-03-27 07:29:35
Scrolling background causes no lag now thanks alot for the help guys!


Edit: It still causes minor lag when I try to load more parts of the same image, but I'll try fix that.

Edit2: Load large background Image is making my graphics card's fan pretty loud, why is that? I can play some pretty graphics intensive games like crysis, fallout3 and the fan would be abit loud, but aren't 2D games less graphics intensive?
19  Game Development / Newbie & Debugging Questions / Re: Load large background image on: 2010-03-27 03:46:09
O that looks interesting, I'll try it out and see how it goes  Grin
20  Game Development / Newbie & Debugging Questions / Re: Load large background image on: 2010-03-26 02:29:13
Hi guys, thanks alot for the replies! I have loaded the background image into an array first( tiles are in a separate array). I'll try the drawImage(Image largeBackgroundImage,sx,sy,sx2,sy2,dx,dy,dx2,dy2,null) method as soon as I get off work. I'm just curious, what's better for performance:
- drawImage(Image largeBackgroundImage,sx,sy,sx2,sy2,dx,dy,dx2,dy2,null)
- getSubImage from bufferedImage(seems like this is really bad for performance)
- store the image into an int array like suggested int array[2363 X 1265], althought I'm not quite sure how to do this one, do  you mean store the pixels into the array?

Again, thanks alot for the help guys!
21  Game Development / Newbie & Debugging Questions / Load large background image on: 2010-03-25 14:49:09
Hi, this probably came up before, but I'm just wondering how are you guys dealing with loading large background images? I have a tile based map and my entire map is consist of 72 X 72 tiles, I have no problem building the map, just when it comes to loading a large background its lagging my game pretty badly. How would you guys load an 2363 X 1265 background image?

I've thought about chopping it into blocks, but that would be harder to do parallel scrolling, my idea is use the getSubImage method from the bufferImage to do the scrolling, but with large image lagging my game this doesn't seem viable. Any tips welcome, thanks in advance.  Grin
22  Game Development / Newbie & Debugging Questions / Re: help with scrolling terrain on: 2010-03-23 03:59:43
I assume vertical  scrolling is working correctly already, all you have to do is change the scrolling Y to scrolling X and there's your horizontal scrolling. You probably also want to change your maps to fit horizontal scrolling.

Your current map:
________
|              |
|              |
|              |
|              |
|              |
|              |
|_______|


Change to:

__________________
|                                  |
|                                  |
|                                  |
|_________________|


Hope that helps, if you still don't get it try this site, its written in flash, but the concept is the same.
http://www.tonypa.pri.ee/tbw/start.html
23  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-03-12 02:43:55
Aaaah, yes I've had rounding errors like that too. I typically would typecast to an int as you did or instead of looking for equality subtracting them and looking for a range less than 0.00001 or something.

Yea, type cast is a magnificent tool  Grin
24  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-03-11 03:18:02
Well - what was it?

Also, congrats on finding it! Way to persevere.

The problem was at the if statement that checks if player is moving from a higher tile onto a slope. I made some slight modifications and added (int) cast to the check and it works  Grin  There are still some minor bugs like mini screen shake when moving on slope and the moving from slopt -> higher tile not playing the correct running animation(it plays jumping), but other than that the slope is looking good, now I need to work on shifting player from Map 1 to a different map and I have a half working game  Grin Thanks again for the help!

This here fix the jump bug:
1  
2  
3  
4  
5  
   
/** Enter slope from higher tile */
      if(map.onSlope(tileX, tileY + 1) && !jumping) {
         py = tileY + 0.4f;
      }



Here's the working code
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  
/** Check if there's a slope and shift Y according to it */
   int prevSlopeType = -1;
   private void checkSlope(float x, float y) {
      /** X used for slope check */
      float checkX = x + sizeW / 2;
      /** Y used for slope check */
      float checkY = y + sizeH;
     
      int tileX = (int)checkX;
      int tileY = (int)checkY;
     
      int slopeType = map.slopeStyle(tileX, tileY);
     
      /** Enter slope from higher tile */
      if(map.onSlope(tileX, tileY + 1) && !jumping) {
         py = tileY + 0.4f;
      }
      /** On slope, shift Y, ignore check if jumpDistance < 0, ie player jumping up */
      if(map.onSlope(tileX, tileY) && !(jumping && jumpDistance < 0)) {
         onSlope = true;
         jumping = false;
         idle = false;
         float xpos = checkX - tileX;
         if(slopeType == Map.SLOPE_L) {
            prevSlopeType = Map.SLOPE_L;
            py = tileY + 1 - sizeH - xpos;
         }
         if(slopeType == Map.SLOPE_R) {
            prevSlopeType = Map.SLOPE_R;
            py = tileY + 1 - sizeH - (1 - xpos);
         }
      } else {
         if((prevSlopeType == Map.SLOPE_L && faceDir == States.RIGHT) || (prevSlopeType == Map.SLOPE_R && faceDir == States.LEFT)) {
            py = tileY - sizeH - 0.1f;
         }
         onSlope = false;
         prevSlopeType = Map.NOT_ON_SLOPE;
      }
   }

25  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-03-10 14:08:32
I've found my bug and fixed it, now my slope is looking good, thanks for everyone that has helped me!  Grin
26  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-03-07 04:42:22
my 2cents help... as I did not really not understand the whole stuff Smiley

according to your draw and if I understand right... may be this one is wrong :
1  
2  
3  
/** moving from a plateform down to the slope */
      } else if(map.onSlope(x + sizeW / 2, y  + 1) && !jumping) {
         onSlope = true;


no ?

"y+1" may be replaced by "y-1 or - 2 - 3"   ? or something like that

"y + 1"  is intended to check for slope below player,  wouldn't y-1, -2 be checking the slope above player? I think my problem happens when entering/exiting the slope, so I'm doing the check suggested by Nate now and I'll post back with the results. Thanks again for the help =)



Here are the test results:

Note:
- checkX/checkY is the X/Y position to check slope collision(where the white square is)

- onSlope is a boolean to tell if player is currently on a slope

- playerX/playerY is the current position of player(top left of the blue square)


1) Entering slope from a higher tile, from tile 6 -> 7 in X direction, tile 2 -> 3 in Y direction


  checkX      checkY   onSlope     playerX      playerY
6.0249996   2.96       false            5.7            2.31
6.0249996   2.96       false            5.7            2.31
6.0249996   2.96       false            5.7            2.31
6.0249996   2.96       false            5.7            2.31
6.0249996   2.96       false            5.7            2.31


2) When player X is somewhere near 6.0, the jump bug occurs (5.99999999..../6.0111111111..... will cause this problem too)

  checkX      checkY   onSlope     playerX      playerY
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325         2.96        false          6.0           2.31
  6.325       3.8730001 true           6.0       2.3249998
  6.325         2.975      false          6.0       2.3249998
  6.325         2.975      false          6.0       2.3249998
  6.325         2.975      false          6.0       2.3249998
  6.325         2.975      false          6.0       2.3249998
  6.325         2.975      false          6.0       2.3249998
  6.325        3.8525     true           6.0       2.3249998

3)From playerX = 6.1 onwards everything is fine, the first couple onSlope = false is when player is falling onto the slope.



  checkX      checkY   onSlope     playerX      playerY
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997     2.96       false          6.1            2.31
6.4249997    3.8725    true           6.1         2.4249997
6.4249997 3.0749998  true          6.1         2.4249997
.
.
.
.
.
6.4249997 3.0749998  true 6.1 2.4249997
27  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-03-06 17:05:29
Ok, thanks I was on a trip and I just got back I'll do that once I'm free, thanks for the reply!
28  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-02-28 04:16:48
I think I've found the problem of my jumping bug, its actually the problem of my slope checking method. I'll explain with a picture so its easier to understand.
- The blue square is the player, and the center buttom white square is my check point used to check for slope(highlighted by green circle)

-The part highlighted by red circle is where my problem is.

The Slope method works fine in picture 1 and 2, I can move up and down, jump on the slope and its all working fine.

I think in picture 3 its suppose start shifting player to the correct Y displacement, but for some reason the onSlope boolean is false(only shift player if its true) and player shifting never takes place until step 4. I have tried adding an if statement to check if the re is a slope below the player when he's moving from a high tile onto slope but that didn't work out either. I've spent days on this problem so any help would be greatly appreciated. Thanks in advance!

if statement to check if a player is moving from a high tile onto slope
1  
2  
3  
4  
if(map.onSlope((int)checkX, (int)y + sizeH)) {
         onSlope = true;
         moveY(moveSpeed);
      }




29  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-02-26 14:52:07
This will probably exceed the word limit of a post so I post the collision part here.

Code to move player, inside it "validLocation" checks the collision( this is from Kevin Glass's tutorial at coke and code
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  
/** Move x and check collision  2010-1-10 */
   public boolean moveX(float dx) {
      /**  work out what the new position of this entity will be */
      float nx = px + dx;
     
      /** Check if next location is a valid one */
      if (validLocation(nx, py)) {
         // if it doesn't then change our position to the new position
        px = nx;
         return true;
      }
     
      /** If blocked don't move */
      return false;
   }
   
   /** Move y and check collision  2010-1-10 */
   public boolean moveY(float dy) {
      /** work out what the new position of this entity will be */
      float ny = py + dy;
     
      /** Check if next location is a valid one */
      if (validLocation(px, ny)) {
         // if it doesn't then change our position to the new position
        py = ny;
         return true;
      }
     
      /** If blocked don't move */
      return false;
   }



Collision Check code:
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  
/** Tile Collision Check */
   private boolean validLocation(float nx, float ny) {
      if(!onSlope) {
         /** Up Left */
         if (map.blocked(nx, ny)) {
            return false;
         }
         /** Up Right */
         if (map.blocked(nx + sizeW, ny)) {
            return false;
         }
         /** Down Left */
         if (map.blocked(nx, ny + sizeH)) {
            /** If player is jumping, change state to IDLE */
            if(jumping) {
               jumping = false;
               jumpDistance = 0;
               idle = true;
            }
            return false;
         }
         /** Down Right */
         if (map.blocked(nx + sizeW, ny + sizeH)) {
            /** If player is jumping, change state to IDLE */
            if(jumping) {
               jumping = false;
               jumpDistance = 0;
               idle = true;
            }
            return false;
         }
      }
     
      /** If none blocked, return true*/
      return true;
   }
30  Game Development / Newbie & Debugging Questions / Re: Jumping character goes through slope on: 2010-02-26 14:45:29
Hm, well shouldn't the jumping be linked to a button press, so he can't jump if no button is being pressed at all?

Also your code seems to be weirdly coupled, which will give you lots of problems. Collision, jumping, etc. should all be separate, not mashed together like that. Something like the pseudo code below:

Does that maybe enlighten you at all?

Thanks for the reply Demonpants! Thanks for the pseudo code too! Actually I do link jumping to a button, below I'll post my code for the missing part of my code. Also the fallCheck method from previous post is to check whether a player is standing on a walkable tile or not, if not then it moves player down, the actual jumping still requires a player to press the space bar.

Handle key for jumping
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
/** Handle key press */
   public void keyPressed(KeyEvent e) {
   //Handle other inputs here, left/right/attack etc
     /** Jumping */
      if (e.getKeyCode() == KeyEvent.VK_SPACE && !jumping && !attacking && !pressSpace) {
         space = true;
         pressSpace = true;
      }
   }
   
   /** Handle key release */
   public void keyReleased(KeyEvent e) {  
         //Handle other input here, left/right/attack etc

      /** Jumping */
      if(e.getKeyCode() == KeyEvent.VK_SPACE) {
         space = false;
         pressSpace = false;
      }
   }


And in the actual update method
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
public void update(long elapsedTime) {
      float dx = 0, dy = 0;
     
      moveSpeed = 0.1f;
      moveSpeed *= elapsedTime * 0.05f;

                /** Player jumping*/
      if(space && !jumping) {
         if(anim.getCurrentState() == States.ATTACKING ||              
                             anim.getCurrentState() == States.HIT) {
         } else {
            idle = false;
            jumping = true;
            jumpDistance = maxJumpHeight;
         }
      }

               /** Make player jump */
      jump(elapsedTime);
}



jump method is called here
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  
/** Makes player jump */
   private void jump(long elapsedTime) {
      /** Check if player is jumping */
      if(jumping) {
         idle = false;
         /** Increase gravity */
         jumpDistance += gravity;
         //jumping up
        if(jumpDistance < 0) {
            /** Check if hits roof */
            if(validLocation(px, py - moveSpeed)) {
               moveY(-moveSpeed);
            } else {
               jumpDistance = 0;
            }
         // Falling down
        } else if(jumpDistance > 0) {
            moveY(moveSpeed);
         }
         /** Set Jumping Animation */
         if(States.JUMPING > anim.getCurrentState()) {
            anim.setCurrentState(States.JUMPING);
         }
         
         /** Update animation */
         updateAnim(elapsedTime);
      }
   }


Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!