Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Canvas setting background Image for games/Other Canvas<Solved>  (Read 10675 times)
0 Members and 1 Guest are viewing this topic.
Offline JayTech

Junior Duke


Medals: 1



« Reply #30 - Posted 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;

      }
}
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #31 - Posted 2012-03-25 21:13:27 »

Yeah, you basically just keep time for each animation frame. However, it's best to organize this into a more OO way. Check out my Animation class.

Offline JayTech

Junior Duke


Medals: 1



« Reply #32 - Posted 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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #33 - Posted 2012-03-25 21:50:36 »

Increasing the FPS should decrease the deltaTime value, which should keep the movement speed the same.

Offline JayTech

Junior Duke


Medals: 1



« Reply #34 - Posted 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();
   }
   
}
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #35 - Posted 2012-03-25 22:07:34 »

It looks fine, but I wonder why you send a millisecond to the update method. You also have a time leak in there.

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

Consider this loop:
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  
public void gameLoop() {
    final long DESIRED_LOOP = Math.round(1e9 / FPS);
   
    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)
                Thread.sleep(1);
            else
                Thread.yield();
        }
    }
}

public void render() {
    do{
        do{
            Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
           
            b3.paint(g);
           
            g.dispose();
        }while(strategy.contentsRestored());
       
        strategy.show();
    }while(strategy.contentsLost());
}

Offline JayTech

Junior Duke


Medals: 1



« Reply #36 - Posted 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();
   }
   
}
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #37 - Posted 2012-03-26 00:35:28 »

Oh yeah Thread.sleep(1) needs try-catch XD

1 million nanos is 1 millisecond Wink

To get delta,  divide deltaTime by 1e9.

Offline JayTech

Junior Duke


Medals: 1



« Reply #38 - Posted 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();
   }
   
}
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #39 - Posted 2012-03-26 01:54:51 »

deltaTime/1e9 * 1000 is the same as deltaTime/1e6.

And yeah, everything looks fine Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JayTech

Junior Duke


Medals: 1



« Reply #40 - Posted 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?
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #41 - Posted 2012-03-26 02:43:30 »

Yeah a fillRect or clearRect is needed, unless you already have a background image.

Offline JayTech

Junior Duke


Medals: 1



« Reply #42 - Posted 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 =).
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (26 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!