Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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 3
1  Game Development / Newbie & Debugging Questions / Re: Can someone please explain this to me :) on: 2013-01-19 21:55:36
Ah, ok makes sense I wrote some tests to verify to further my understanding. Still manage to confuse myself sometimes even though I have a more than novice skill set in java lol.
And yes I know how C++ pointers work for the most part



Thanks for all the responses/help Smiley
2  Game Development / Newbie & Debugging Questions / Re: Can someone please explain this to me :) on: 2013-01-19 05:26:53
Right I understand that however I don't understand how we are linking
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
         BufferedImage.TYPE_INT_ARGB);
int pixels[]                      =      ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
^ This is just copying                   this?^

^but how does editing this             have any effect on ^
Since we are just copying the right to the left?


My only assumption is that this is working as pass by reference, I didn't realize java allows pass by reference for arrays?
Scratch that right..java is only pass by value
3  Game Development / Newbie & Debugging Questions / Re: Can someone please explain this to me :) on: 2013-01-19 05:17:29
I'm still confused, Image is independent. Then you are saying pixel array is equal to the contents of image so now pixels has the contents of Image however how does that change image's contents.

I mean I would imagine this,
Image = pixels;

but we have so..
pixels = image is only setting the contents of pixels to image not the reverse right?
4  Game Development / Newbie & Debugging Questions / Can someone please explain this to me :) on: 2013-01-19 05:00:04
Experimenting with a new way to render images, trying to understand what notch did with his rendering which is quite popular for Java games now, I'm slightly confused on how this bit of code is working.

1  
2  
3  
4  
5  
6  
7  
8  
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
         BufferedImage.TYPE_INT_ARGB);
int pixels[] = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

and then..
render(Graphics g){
 g.drawImage(image..etc)
}

How is editing pixels affecting image?
5  Game Development / Newbie & Debugging Questions / Re: Method not working w/o Sys.outs...Please help am baffled on: 2012-05-28 23:25:41
Meaning it doesn't work is that the thread just doesn't go/stop if I take the Sys outs away.
The object of this method is to start a loop which it looks at my games System time and takes a snapshot of the current time and then designated time to time something for example if its 30secs game time and you want 5seconds of something to start or sleep it goes till 35secs then terminates.

TEtarget.GEStart(); is the TimerEvent classes calling to a Interface method  GEStart which is passed through the constructor during initialization of the object. GeStart can be anything its just like Runnable.

 if (TimeWizard.mainTimeSecs <= currTime) once false it = else and  eventContinue to false ending the while loop.

Btw this is added to a thread.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void teGO() {
      new Thread(this).start();

   }

   @Override
   public void run() {
      this.startEvent();

   }


End result  
1  
new TimedEvent(9,this).teGO();


Pretty much this class is a custom timer running by my games system time. Any entity or object can use this to trigger events because I have a method which tells once this is finished or not via TimerEvents method which other classes check.
1  
2  
3  
public boolean eventStatus() {
      return eventAlive;
   }


You are able to pick a time to Run during the duration say for 5 seconds or choose to go after 5 seconds  eventForDuration =true then it goes for the designated duration otherwise false it goes after the set duration.


So yea it appears my thread is just hanging for some reason.

EDIT: Solved..yea changing from a boolean to a void fixed things and just cleaning the code a bit, thanks guys UprigthPath good calls btw.
6  Game Development / Newbie & Debugging Questions / <Solved>Method not working w/o Sys.outs...Please help am baffled on: 2012-05-28 21:45:37
<Solved>
Thanks all.


Apparently threads don't like boolean methods ><. My headache is gone alas!
7  Java Game APIs & Engines / Java 2D / Re: 2DGraphics PixelArray vs G2d.drawImage(...).. on: 2012-04-22 21:54:16
Thanks for the responses, I mean is there one that is more professional than another? Do you all just use Draw when making a game, is it acceptable for an app? Does one get higher fps than another? I just really want to make sure before I put the cap on my game's graphical capabilities =D
8  Java Game APIs & Engines / Java 2D / 2DGraphics PixelArray vs G2d.drawImage(...).. on: 2012-04-22 00:44:51
Ok, so i'm just starting to finish my GFx API in my game  and I've watched some tutorials where people add every entity into the games Pixel array instead of just doing g2d.draw(image,x,y) to a Canvas, they instead do pixel raster to images. Is this really needed or is G2D.draw(bufferedimages) suffice for mediocre game. My game art style is a 2D sidescroller like type gamerpg such as Dungeon Fighter online etc.

My question is, what benefits are there to using pixel arrays? Is this needed for my type of game? Also is this easy to integrate?

Thanks in advance,
Tips*hat*
Jay
9  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas<SOLVED> on: 2012-03-26 03:10:59
http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferStrategy.html


Read up on bufferstrategy  Smiley

Alright well thanks for all the help on this thread everyone going to tag this thread as solved, hopefully some other forum members can read this thread and learn something new as I did. Anways for now, back to more researching and coding on my game hopefully going to finish the rest of my graphics classes API and implement all the lvls, npcs, battle engine in soon..finally being able to convert my text based RPG into an actualy 2D game is great =).
10  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-26 02:00:23
 
Quote
deltaTime/1e9 * 1000 is the same as deltaTime/1e6.
Ah true XD



Still a bit confused on
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void render() {
       do{
           do{
               Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
               
               b3.paint(g);
               
               g.dispose();
           }while(bufferStrategy.contentsRestored());
           
           bufferStrategy.show();
       }while(bufferStrategy.contentsLost());
   }


   As Opposed to
  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void render() {
      Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
     g.clearRect(0, 0, WIDTH, HEIGHT);
     b3.paint(g);
     g.dispose();
    bufferStrategy.show();

       
       
   }

 

   I thought that clearRect was needed?
11  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-26 01:01:38
This is correct right?

1  
2  
3  
4  
5  
6  
7  
  protected void update(long deltaTime){
     
      //b3.setDelta(deltaTime);
     
      b3.update((int)((deltaTime/1e9)*1000));
   
   }


Also can you explain exactly what is going on here?

The render that you gave me.
 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void render() {
       do{
           do{
               Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
               
               b3.paint(g);
               
               g.dispose();
           }while(bufferStrategy.contentsRestored());
           
           bufferStrategy.show();
       }while(bufferStrategy.contentsLost());
   }


Ok everything is ALOT smoother, although Images are now somewhat jittery. Is there something that I don't have here that is making it do so?




 is this paint method  correct? Do I need to add any thing, no disposing no super.paint right? the main game class will handle that in the render loop right?
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  
public void paint(Graphics2D g) {
      //super.paint(g);
       
      // Rectangle r = new Rectangle(playerSprite.getX() - 5, playerSprite.getY() - 40, 70, 10);
     
     
     
      g.drawImage(bg, 0, 0, this);
     
     
      g.setColor(Color.RED);
      g.fillRect(playerSprite.getX() - 5, playerSprite.getY() - 40, playerSprite.returnHealth(), 10);// healthbar
                                                        // fill
     g.setColor(Color.GREEN);
      g.drawRect(playerSprite.getX() - 5, playerSprite.getY() - 40, 70, 10);

      g.setColor(Color.GREEN);
      g.drawString(playerSprite.getMTag(), playerSprite.getX() - 20, playerSprite.getY() - 10); // Monster
                                                  // Name
     

      g.drawImage(playerSprite.getsprite(), playerSprite.getX(), playerSprite.getY(), this);// Monster
                                                     // Sprite

      monsterSprite.Render(g);

     
     
      // ED.tempmhp);
     //g.drawImage(UI, 350,600,600,90, this);
     fps(g);
     
   }















========================Everything in main========================================================================
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  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;



public class Game implements Runnable{
   
   
   //
  BufferedImageLoader BuffLoad = new BufferedImageLoader();
   BufferedImage sprite_sheet = null;
   BufferedImage sprite;
   Image image;
   ImageIcon ii ;
   
   public Board3 b3;  
   //
   int WIDTH = 0;
       int HEIGHT = 0;
   SonageArenaFrame SAF;
   JFrame frame;
   Canvas canvas;
   BufferStrategy bufferStrategy;
   
   public Game(){
     
      frame= new JFrame("DemoCanvas");
     //. frame = new JFrame("Demo Canvas");
     b3= new Board3();

      WIDTH=b3.bg.getWidth(null);
      HEIGHT= b3.bg.getHeight(null);
      frame.add(SAF.p, "South");
     JPanel panel = (JPanel) frame.getContentPane();
     
      panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
      panel.setLayout(null);
     
      canvas = new Canvas();
      canvas.addKeyListener(new TAdapter());
      canvas.setBounds(0, 0, WIDTH, HEIGHT);
      canvas.setIgnoreRepaint(true);
     
      panel.add(canvas);
     
      canvas.addMouseListener(new MouseControl());
     
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setResizable(true);
      frame.setVisible(true);
   
     
     
     
     
     
      canvas.createBufferStrategy(3);
      bufferStrategy = canvas.getBufferStrategy();
     
      canvas.requestFocus();
   }
   
       
   private class MouseControl extends MouseAdapter{
     
   }
   
   long desiredFPS =60;
 
   
   boolean running = true;
   
   public void run() {
       final long DESIRED_LOOP = Math.round(1e9 / desiredFPS);
       
       long lastTime = System.nanoTime();
       
       while(true) {
           long deltaTime = System.nanoTime() - lastTime;
           lastTime += deltaTime;
         
           update(deltaTime);
           
           render();
           
           long sleepTime = Math.round((DESIRED_LOOP)-(System.nanoTime()-lastTime));
           if(sleepTime <= 0)
               continue;
           
           long prevTime = System.nanoTime();
           while(System.nanoTime()-prevTime <= sleepTime) {
               if(System.nanoTime()-prevTime <= sleepTime * 0.9)
               try {
                  Thread.sleep(1);
               } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                 e.printStackTrace();
               }
            else
                   Thread.yield();
           }
       }
   }
   
   public void render() {
       do{
           do{
               Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
               
               b3.paint(g);
               
               g.dispose();
           }while(bufferStrategy.contentsRestored());
           
           bufferStrategy.show();
       }while(bufferStrategy.contentsLost());
   }
   
   //TESTING
 
   /**
    * Rewrite this method for your game
    */

   protected void update(long deltaTime){
     
      //b3.setDelta(deltaTime);
     
      b3.update((int)((deltaTime/1e9)*1000));
      System.out.println((int)((deltaTime/1e9)*1000));
   }
 
   /**
    * Rewrite this method for your game
    */

   protected void render(Graphics2D g){
   
    b3.paint(g);
   }
   private class TAdapter extends KeyAdapter {

      public void keyReleased(KeyEvent e) {
         b3.playerSprite.keyReleased(e);
      }

      public void keyPressed(KeyEvent e) {
         b3.playerSprite.keyPressed(e);
      }
   }
   public static void main(String [] args){
      Game ex = new Game();
      new Thread(ex).start();
   }
   
}
12  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 22:19:02
First off are you giving me permission to use that game loop in my game? Second I pasted the code in Eclipse to try it out and it's saying I need try/catch block XD might want to edit that.

EDIT: Gotcha
Quote
EDIT: Oh and you are supposed to be using BufferStrategy in a certain way. Refer to code Smiley



Also I tried out everthing and am getting very weird resutls flashing screen and such.



--------------------------------------------------------------------------------------------------------------------------------------------------

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  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Game implements Runnable{
   
   final int WIDTH = 1366;
   final int HEIGHT = 768;
   //
  BufferedImageLoader BuffLoad = new BufferedImageLoader();
   BufferedImage sprite_sheet = null;
   BufferedImage sprite;
   Image image;
   ImageIcon ii ;
   public Image bg;
   public Board3 b3;  
   //
  SonageArenaFrame SAF;
   JFrame frame;
   Canvas canvas;
   BufferStrategy bufferStrategy;
   
   public Game(){
     
     
      frame= new JFrame("DemoCanvas");
     //. frame = new JFrame("Demo Canvas");
     b3= new Board3();
     
      frame.add(SAF.p, "South");
     JPanel panel = (JPanel) frame.getContentPane();
     
      panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
      panel.setLayout(null);
     
      canvas = new Canvas();
      canvas.addKeyListener(new TAdapter());
      canvas.setBounds(0, 0, WIDTH, HEIGHT);
      canvas.setIgnoreRepaint(true);
     
      panel.add(canvas);
     
      canvas.addMouseListener(new MouseControl());
     
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setResizable(true);
      frame.setVisible(true);
      try {
         bg = javax.imageio.ImageIO.read(new java.net.URL(getClass()
               .getResource("/Trees!.png"), "Trees!.png"));
      } catch (Exception eee) {
         System.out.println(eee.toString());
      }
     
     
      ii =
              new ImageIcon(this.getClass().getResource("/FireFlame.png"));
     
      try {
         sprite_sheet = BuffLoad.loadImage("/PetSword2.png");
      } catch (IOException IEE) {
      }
      //ss = new SpriteSheet(sprite_sheet);
     
     
      canvas.createBufferStrategy(3);
      bufferStrategy = canvas.getBufferStrategy();
     
      canvas.requestFocus();
   }
   
       
   private class MouseControl extends MouseAdapter{
     
   }
   
   long desiredFPS =60;
 
   
   boolean running = true;
   
   public void run() {
       final long DESIRED_LOOP = Math.round(1e9 / desiredFPS);
       
       long lastTime = System.nanoTime();
       
       while(true) {
           long deltaTime = System.nanoTime() - lastTime;
           lastTime += deltaTime;
           
           update(deltaTime);
           
           render();
           
           long sleepTime = Math.round((DESIRED_LOOP)-(System.nanoTime()-lastTime));
           if(sleepTime <= 0)
               continue;
           
           long prevTime = System.nanoTime();
           while(System.nanoTime()-prevTime <= sleepTime) {
               if(System.nanoTime()-prevTime <= sleepTime * 0.9)
               try {
                  Thread.sleep(1);
               } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                 e.printStackTrace();
               }
            else
                   Thread.yield();
           }
       }
   }
   
   public void render() {
       do{
           do{
               Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
               
               b3.paint(g);
               
               g.dispose();
           }while(bufferStrategy.contentsRestored());
           
           bufferStrategy.show();
       }while(bufferStrategy.contentsLost());
   }
   
   //TESTING
 
   /**
    * Rewrite this method for your game
    */

   protected void update(long deltaTime){
     
      //b3.setDelta(deltaTime);
     
      b3.update((int)deltaTime);
   System.out.println(deltaTime);
   }
 
   /**
    * Rewrite this method for your game
    */

   protected void render(Graphics2D g){
   
    b3.paint(g);
   }
   private class TAdapter extends KeyAdapter {

      public void keyReleased(KeyEvent e) {
         b3.playerSprite.keyReleased(e);
      }

      public void keyPressed(KeyEvent e) {
         b3.playerSprite.keyPressed(e);
      }
   }
   public static void main(String [] args){
      Game ex = new Game();
      new Thread(ex).start();
   }
   
}
13  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 21:57:40
Doesn't seem to do so though the higher Increase the FPS the faster objects are moving XD.

Also from switching from my JPanel setup/non delta gameloop to this and canvas I've noticed some choppiness not sure why..performance hasn't gone up, I must've fked something up..




Main game Loop from the tutorials section that i'm using until I make my own/master delta time and canvas

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  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Game implements Runnable{
   
   final int WIDTH = 1366;
   final int HEIGHT = 768;
   //
  BufferedImageLoader BuffLoad = new BufferedImageLoader();
   BufferedImage sprite_sheet = null;
   BufferedImage sprite;
   Image image;
   ImageIcon ii ;
   public Image bg;
   public Board3 b3;  
   //
  SonageArenaFrame SAF;
   JFrame frame;
   Canvas canvas;
   BufferStrategy bufferStrategy;
   
   public Game(){
     
     
      frame= new JFrame("DemoCanvas");
     //. frame = new JFrame("Demo Canvas");
     b3= new Board3();
     
      frame.add(SAF.p, "South");
     JPanel panel = (JPanel) frame.getContentPane();
     
      panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
      panel.setLayout(null);
     
      canvas = new Canvas();
      canvas.addKeyListener(new TAdapter());
      canvas.setBounds(0, 0, WIDTH, HEIGHT);
      canvas.setIgnoreRepaint(true);
     
      panel.add(canvas);
     
      canvas.addMouseListener(new MouseControl());
     
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setResizable(true);
      frame.setVisible(true);
      try {
         bg = javax.imageio.ImageIO.read(new java.net.URL(getClass()
               .getResource("/Trees!.png"), "Trees!.png"));
      } catch (Exception eee) {
         System.out.println(eee.toString());
      }
     
     
      ii =
              new ImageIcon(this.getClass().getResource("/FireFlame.png"));
     
      try {
         sprite_sheet = BuffLoad.loadImage("/PetSword2.png");
      } catch (IOException IEE) {
      }
      //ss = new SpriteSheet(sprite_sheet);
     
     
      canvas.createBufferStrategy(3);
      bufferStrategy = canvas.getBufferStrategy();
     
      canvas.requestFocus();
   }
   
       
   private class MouseControl extends MouseAdapter{
     
   }
   
   long desiredFPS =60;
   long desiredDeltaLoop = (1000*1000*1000)/desiredFPS;
   
   boolean running = true;
   
   public void run(){
     
      long beginLoopTime;
      long endLoopTime;
      long currentUpdateTime = System.nanoTime();
      long lastUpdateTime;
      long deltaLoop;
     
      while(running){
         beginLoopTime = System.nanoTime();
         
         render();
         
         lastUpdateTime = currentUpdateTime;
         currentUpdateTime = System.nanoTime();
         update((int) ((currentUpdateTime - lastUpdateTime)/(1000*1000)));
         
         endLoopTime = System.nanoTime();
         deltaLoop = endLoopTime - beginLoopTime;
           
           if(deltaLoop > desiredDeltaLoop){
               //Do nothing. We are already late.
          }else{
               try{
                   Thread.sleep((desiredDeltaLoop - deltaLoop)/(1000*1000));
               }catch(InterruptedException e){
                   //Do nothing
              }
           }
      }
   }
   
   private void render() {
      Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
      g.clearRect(0, 0, WIDTH, HEIGHT);
      render(g);
      g.dispose();
      bufferStrategy.show();
   }
   
   //TESTING
 
   /**
    * Rewrite this method for your game
    */

   protected void update(int deltaTime){
     
      //b3.setDelta(deltaTime);
     
      b3.update(deltaTime);
   System.out.println(deltaTime);
   }
 
   /**
    * Rewrite this method for your game
    */

   protected void render(Graphics2D g){
   
    b3.paint(g);
   }
   private class TAdapter extends KeyAdapter {

      public void keyReleased(KeyEvent e) {
         b3.playerSprite.keyReleased(e);
      }

      public void keyPressed(KeyEvent e) {
         b3.playerSprite.keyPressed(e);
      }
   }
   public static void main(String [] args){
      Game ex = new Game();
      new Thread(ex).start();
   }
   
}
14  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 21:25:53
So yes we do keep track of time by adding deltas MS/ns to a counter right?
Also ,from what i've said before about upping fps for delta and objects moving too fast, is it because logic is going too fast? I thought delta time was supposed to take care of this fully?
15  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas...<Solved> on: 2012-03-25 20:51:18
Ok so..

if
xVel= 3;
delta = 14/1000 = .014
xPos += (xVel * delta);

?

And you're saying this should sync things further?..

Also am I understanding Delta? such as in a board class passing through delta to other classes where I can control time such as adding counters to delta and then testing time such as delta being passed into my sprite class's setTick method? This is really the only thing I don't seem to understand in game design..other wise I feel that i'm ready to move on with my game, but as of now this is the only problem i'm having with graphics and time updating.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
//MOnster sprite set tick method keeps control time to add to loops which add or subtract movement and update logic
public void setTick(int delta) {
      tick += delta; Main sprite tick for movement
      mainTime += delta;//Control of time for seconds and minutes
     aniTime += delta;//Animation time 1
     aniTime2+=delta;//Animation time 2
     // System.out.println(tick);
     
      if (tick >= 500) {
         mainSpriteTick++;
          //  fx1tick++;
        //counterTick2++;
        // System.out.println(mainSpriteTick);
        tick = 0;

      }
}
16  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 20:10:28
So for xVelocity I want my sprite to move 3pixels but with a delta time of 14ms I'd be moving at 42pixels per second?

How can I make sure I just move x pixles perSecond? This is in regards of a simple RPG. Btw I should be using delta time for keeping track of ALL time right? Or am I confused with the purpose of delta time?
17  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 19:57:33
Is my logic correct?  Such as accumulating delta time and updating stuff w.e time I want like 500ms? And where should I be multiplying delta?
For example In my setTick Method in my monster Sprite class for my main sprite movement it updates every 500ms.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void setTick(int delta) {//
     tick += delta;
      mainTime += delta;
      aniTime += delta;
      aniTime2+=delta;
      // System.out.println(tick);
     
      if (tick >= 500) {
         mainSpriteTick++;
          //  fx1tick++;
        //counterTick2++;
        // System.out.println(mainSpriteTick);
        tick = 0;

      }
18  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 17:15:24
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  
 long desiredFPS =100;
   long desiredDeltaLoop = (1000*1000*1000)/desiredFPS;
   
   boolean running = true;
   
   public void run(){
     
      long beginLoopTime;
      long endLoopTime;
      long currentUpdateTime = System.nanoTime();
      long lastUpdateTime;
      long deltaLoop;
     
      while(running){
         beginLoopTime = System.nanoTime();
         
         render();
         
         lastUpdateTime = currentUpdateTime;
         currentUpdateTime = System.nanoTime();
         update((int) ((currentUpdateTime - lastUpdateTime)/(1000*1000)));
         
         endLoopTime = System.nanoTime();
         deltaLoop = endLoopTime - beginLoopTime;
           
           if(deltaLoop > desiredDeltaLoop){
               //Do nothing. We are already late.
          }else{
               try{
                   Thread.sleep((desiredDeltaLoop - deltaLoop)/(1000*1000));
               }catch(InterruptedException e){
                   //Do nothing
              }
           }
      }
   }

1  
2  
3  
4  
5  
protected void update(int deltaTime){
      //b3.setDelta(deltaTime);
     b3.update(deltaTime);
   System.out.println(deltaTime);
   }

Then I take delta pass it through update which is then passed through set delta method to my board class  b3.update(delta time) that is then passed through for other methods dealing with time such as animations and movement. Or is that incorrect? The other methods in the board class such as playerSprite.setTime(takes in delta from the board class) and then looks over that time and checks if seconds go by or minutes to do game updates based on the overall delta time of the main games time.

Example of MonsterSprites methods dealing with delta time.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void setTick(int delta) {//Time is money..
     tick += delta;
      mainTime += delta;
      aniTime += delta;
      aniTime2+=delta;
      // System.out.println(tick);
     
      if (tick >= 500) {
         mainSpriteTick++;
          //  fx1tick++;
        //counterTick2++;
        // System.out.println(mainSpriteTick);
        tick = 0;

      }
}


When I set it to 100fps as opposed to60fps  at 100 fps things seem to move slightly faster  than they should like 3 frames tick for monster movement looks like 5-6 at 100fps+.

Isn't this correct? What am I doing wrong??? It appears that my game Logic is faster than it should or should I not even worry about 100fps as long as 60fps stays the same? I was before just using timer every 14ms to update an action preformed method to do update logic and repaint(), found this loop on the forums and it seems much better although, can someone please explain how to sync game logic properly?
Thanks
19  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/Other Canvas/graphic questions on: 2012-03-25 06:51:23
@Above thanks, gotcha =). Also another question for you you guys, I got my canvas working and everything seems fine tri buffering and  my delta time is great but it seems when I go from 60fps to 100 fps animations go a bit too fast, why is this? Why are they moving too fast and not synchronized well, what is the best way to combat this I thought delta time was supposed to do so?
20  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-25 04:03:11
Good point.
21  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games/lvl design on: 2012-03-25 02:35:56
Btw, jammas615 about your message about lvl states. I mean for an average turn base 2d rpg like maybe Fireemblem etc would you consider those lvls? I mean what is the usual standard to switch between lvls/zones? Are lvl/states an efficent way of doing so?
22  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-25 00:41:58
Thanks =).
23  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 23:40:52
Hm, yea that is true. I guess I was confusing the two XD. But I just wanted to make sure I was cleaning up the graphics properly in Canvas, as where Jpanel you could do  clear etc.

Here's a preview of my games engine so far
http://www.youtube.com/watch?v=yd39sCPX-zM

Been finishing the graphics API am almost done, all graphics are place holders till I get a new artist...Need to incorperate the battle engine in soon.

Game preview is in JPanel atm switching to canvas as we speek.

Let me know whatcha think =D.
24  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 21:39:51
Alright cool thanks you guys =).
25  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 21:22:30
@Above that's pretty much what I thought. So each lvl would be a different lvlclasses object right?
26  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 20:45:13
I mean memory wise =D, how is the garbage collection for images, once not drawn all references are gone?
27  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 20:07:51
So my game is an RPG and there will be maybe you will be at an Inn or maybe a dungeon. So you're saying by just loading those classes and each Npc entity etc once I just not draw them they will be gone visually an In memory?
28  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 20:03:50
Thanks man you're always there when I need ya and rebirth too! Hey another question, what should I do for canvas when I want to load another lvl, like clean up  a screen just clear rect? Or what is the proper way to clean up to prepair for another zone?
29  Game Development / Game Play & Game Design / Re: Canvas setting background Image for games on: 2012-03-24 19:44:21
@Ra4king yea I understand that part, but for a background Image in canvas how do I set a static background Image like paint component does in Jpanel or do I just draw it first? I don't want to have to keep re painting it right?
2nd question, to clear a canvas you do clear rect right or something else?
30  Game Development / Game Play & Game Design / Canvas setting background Image for games/Other Canvas<Solved> on: 2012-03-24 06:15:46
So for Canvas is there a way to Paintcomponent like in JPanel? What is the best way to set a background Image? All help is appreciated.
Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
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!