Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sprite Sheet  (Read 3848 times)
0 Members and 1 Guest are viewing this topic.
Offline Cirdan

Senior Newbie




Java games rock!


« Posted 2005-03-21 03:02:18 »

Hello, I have a sprite sheet, were every 32x32 height wise is a different sprite. Wdith wise is each frame of animation. How do I only get a 32x32 block from the big sprite sheet?
Offline DrBizzar0

Junior Member




Raj raj!


« Reply #1 - Posted 2005-03-21 04:42:29 »

Use this drawImage method.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver)

It allows you to specify a subpart of an image to be drawn on a specified place on another image.

On a side note, it's common to load and chop up the tilesets in small images when the game, level or something similar is initialized and then just paint the choped pics.
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #2 - Posted 2005-03-21 10:57:47 »

I think it's actually most efficient to draw using that method and not chop the image up.  Better for considering switching to OpenGL as well.  That's the best way to go in that context also

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2005-03-21 11:07:26 »

Any image larger than 256x256 isn't accelerated behind the scenes (via automatic/volatile images), so on a practical note you'll need to have sub images in order to get good drawing speed.

Last time I tried it, using individual images was somewhat faster than drawing a sub image (even when the master image was less than 256x256).

Don't guess - profile!

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline lefnire

Senior Newbie




Java games rock!


« Reply #4 - Posted 2005-03-21 17:34:28 »

how do you chop up peices of an image and store them as separate images anyway?
Offline Cirdan

Senior Newbie




Java games rock!


« Reply #5 - Posted 2005-03-21 17:42:38 »

Quote
Use this drawImage method.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver)

It allows you to specify a subpart of an image to be drawn on a specified place on another image.

On a side note, it's common to load and chop up the tilesets in small images when the game, level or something similar is initialized and then just paint the choped pics.


Okay thankyou! Now, I made a function to make the ground, which draws a bunch of 32x32 grass tiles over the ground. then after that, it draws the character sprite. now I've coded it so every game loop, it moves right.(x++;) Now, that character sprite flickers, but the ground doesn't. Every loop it draws a 1000 tiles over a 800x600 area. then after it does that, it draws the character sprite, and then refreshes the screen for buffer. but the character sprite flickers but not the ground tiles. could it be because of drawing all the tiles slows it down?

Also, is there a way to draw an image iunto a createImage() variable?
Also can you explain that drawImage code you posted. And is it true I can only have a heightxwidth of 256
Offline Valodim

Junior Member




*sigh*


« Reply #6 - Posted 2005-03-22 00:10:40 »

Quote
could it be because of drawing all the tiles slows it down?


you do use bufferstrategy and the sprite IS drawn every tick? then I have no idea what might be wrong Tongue

Quote

Also, is there a way to draw an image iunto a createImage() variable?


uh... what? do you mean into an imageproducer? o_O

Quote
Also can you explain that drawImage code you posted.


how about reading the docs...?

Quote
And is it true I can only have a heightxwidth of 256


noone ever said that. sprites above 256x256 are just not accelerated (so you should not use them. you may, though)
Offline Cirdan

Senior Newbie




Java games rock!


« Reply #7 - Posted 2005-03-25 03:10:32 »

Sorry for the long time no reply. I got the code working perfectly, now I wish to fix the flickering issue...

Heres my Update()

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  
public void update(Graphics g){
            player.drawAvatar(sprites,player_x,player_y,sprite,dir,g);
           
            //create buffer
           if(buffer == null){
                  buffer = createImage(app_width,app_height);
                  bgraphics = buffer.getGraphics();
            }
            repaint();
           
            bgraphics.setColor(getBackground());
            bgraphics.fillRect(0,0,app_width,app_height);
            repaint();
           
            //Draw Gui
           gui.drawGUI(g,gui1,gui2);
            gui.drawStats(g,25,20,1025,5);
            gui.drawMenu(g);
            bgraphics.setColor(getForeground());
            repaint();
            player.drawAvatar(sprites,player_x,player_y,sprite,dir,g);
            //Draws the appropiate menu that the user clicked
           switch(menu_item){
                  case 0:
                  //do nothing
                 break;
                                   
                  case 1:
                  gui.drawInventory(g);
                  repaint();
                  break;
                 
                  case 2:
                  gui.drawEquipment(g);
                  break;
                 
                  case 3:
                  gui.drawMagic(g);
                  break;
                 
                  case 4:
                  gui.drawMStats(g);
                  break;
                 
                  case 5:
                  gui.drawOptions(g);
                  break;
            }
           
           
            //re-draw map + character
                  for(y = 0; y < 480; y = y + 32){
                         g.drawString("Cirdan",player_x-5,player_y - 15);
                        makeRow(0,y,g);
                        player.drawAvatar(sprites,player_x,player_y,sprite,dir,g);
                        repaint();
                  }
           
           
      }
     
      public void paint(Graphics g){
           
            repaint();
      }


and heres my game 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  
41  
42  
43  
44  
45  
while(true){
                        repaint();
                 
                  if(walk == true){
                        walk = false;
                  } else if(walk = false) {
                        walk = true;
                  }
                 
                 
                  //-----------------------------------------
                  //Checks to see if the user exits the room - BLOCK OF CODE = TEMPORARY
                  //WILL BE USED TO TELEPORT FROM ONE MAP TO ANOTHER
                  //-----------------------------------------
                 if(player_y + 32 > 480){
                        player_y = 0;
                        repaint();
                  }
                 
                  if(player_y < 0) {
                        player_y = 448;
                        repaint();
                  }
                 
                  if(player_x < 0){
                        player_x = 640 - 32;
                        repaint();
                  }
                 
                  if(player_x + 32 > 640){
                        player_x = 0;
                        repaint();
                  }
                  //-----------------------------------------
                 
                                   
                  try{

                  th.sleep(20);

                 
                  } catch(InterruptedException ex){
                       
                  }
           
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2005-03-25 05:47:59 »

What class is that update(Graphics g) method in? What does it inherit from? You could be overriding the real update() method. If so, calling repaint() from inside it probably isn't healthy.

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-03-25 15:42:30 »

Okay, I changed my code. Every thing is drawin in the paint() and the buffer clears the screen throguh the update() But, my gui code won't draw throguh the paint() I get this exception. But if I draw my gui in the update() method, it works, but the text flickers. Any idea?

my draw gui 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  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
public void drawGUI(Graphics g,Image gui1,Image gui2){
            g.drawImage(gui1,640,0,this);
            g.drawImage(gui2,0,480,this);

            //Draw Stats
           
      }
     
      public void drawStats(Graphics g,int hp,int mp,int xp,int level){
            //Set font Color
           g.setColor(Color.white);
           
           
            //Draw the infomation
           g.drawString("HP: " + hp,650,100);
            g.drawString("MP: " + mp,650,115);
            g.drawString("Experience: " + xp,650,130);
            g.drawString("Level: " + level,650,145);
      }
     
      public void drawInventory(Graphics g){
            // y =187
           g.drawString("Inventory",685,200);            
           
      }
     
      public void drawMagic(Graphics g){
            // y = 187
           g.drawString("Magic",700,200);
      }
     
      public void drawOptions(Graphics g){
      g.drawString("Options",695,200);      
      }
     
      public void drawEquipment(Graphics g){
            g.drawString("Equipment",685,200);
      }
     
      public void drawMStats(Graphics g){
            g.drawString("Stats",700,200);
      }
     
      public void drawMenu(Graphics g){
            //y = 437
           
            g.drawString("Menu",700,450);
            g.drawString("Inventory",650,465);
            g.drawString("Equipment",650,480);
            g.drawString("Magic",650,495);
            g.drawString("Stats",650,510);
            g.drawString("Options",650,525);
      }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2005-03-25 16:41:05 »

Maybe if you post the exception  you're getting?

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-03-25 17:12:49 »


Here they are...

http://www.christiangaming.org/graphics/users/Trooper/exception.jpg
http://www.christiangaming.org/graphics/users/Trooper/exception2.jpg
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #12 - Posted 2005-03-25 17:19:11 »

And the two lines mentioned, which are they, since we don't have any lines numbers in the code above?

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #13 - Posted 2005-03-25 17:53:56 »

line 311 and 312 =

which is in update()

1  
2  
bgraphics.setColor(getBackground());
bgraphics.fillRect(0,0,640,480);


Then on line 248:
which is in my game loop

1  
2  
3  
247      try{
248
249      th.sleep(20);


my current update()
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  
public void update(Graphics g){
     
           
            //create buffer
           if(buffer == null){
                  buffer = createImage(app_width,app_height);
                  bgraphics = buffer.getGraphics();
            }

           
           

            //draw gui
           gui.drawGUI(g,gui1,gui2);
            gui.drawStats(g,25,20,1025,5);
            gui.drawMenu(g);
           
            //Draws the appropiate menu that the user clicked
           switch(menu_item){
                  case 0:
                  //do nothing
                 break;
                                   
                  case 1:
                  gui.drawInventory(g);
                  repaint();
                  break;
                 
                  case 2:
                  gui.drawEquipment(g);
                  break;
                 
                  case 3:
                  gui.drawMagic(g);
                  break;
                 
                  case 4:
                  gui.drawMStats(g);
                  break;
                 
                  case 5:
                  gui.drawOptions(g);
                  break;
            }
           
           
            bgraphics.setColor(getBackground());
            bgraphics.fillRect(0,0,640,480);
           
           

           
            paint(bgraphics);

                 
            g.drawImage(buffer,0,0,this);
     


my current game 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  
41  
            while(true){
                        repaint();
                 
                 
                  //-----------------------------------------
                  //Checks to see if the user exits the room - BLOCK OF CODE = TEMPORARY
                  //WILL BE USED TO TELEPORT FROM ONE MAP TO ANOTHER
                  //-----------------------------------------
                 if(player_y + 32 > 480){
                        player_y = 0;
                        repaint();
                  }
                 
                  if(player_y < 0) {
                        player_y = 448;
                        repaint();
                  }
                 
                  if(player_x < 0){
                        player_x = 640 - 32;
                        repaint();
                  }
                 
                  if(player_x + 32 > 640){
                        player_x = 0;
                        repaint();
                  }
                  //-----------------------------------------
                 
                                   
                  try{

                  th.sleep(20);

                 
                  } catch(InterruptedException ex){
                       
                  }
           
               
           

Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2005-03-25 18:37:12 »

Acording to your exceptions, 312 should be where you call updateGUI(). The other line number was 322? Have you been changing the code while reporting the problems?

If possible it might be easier if you post the code as a whole. Null pointers probably just mean paint() is getting called before you've had a chance to create your buffer.

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #15 - Posted 2005-03-25 18:56:36 »

ok, heres my 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  
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  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;


public class SecretsofCelebrindal extends JApplet implements KeyListener,MouseListener,Runnable {
      //-----------------------------------------
     //Variables
     //-----------------------------------------
     
      int app_width,app_height,tiles_y,tiles_x,map_x,map_y,y,x,i,tiles,player_x,player_y, menu_item,dir,sprite;
      public boolean map_created,walk,walking;
      Graphics bgraphics;
      player player;
      gui gui;
      Image grass,sprites,gui1,gui2,buffer,map;
      String name,command;
      char key;
      public Thread th;
      static int keyUp = 38;
      static int keyDown = 40;
      static int keyLeft = 37;
      static int keyRight = 39;
     
     
      //-----------------------------------------
     //Misc. Functions
     //-----------------------------------------
     
      //-----------------------------------------
     //For the map, draw a row - TEMPORARY
     public void makeRow(int mx,int my,Graphics g){
                       
                        for(mx = 0; mx< 640; mx = mx + 32){
                                               
                              g.drawImage(grass,mx,my,this);
                              tiles++;
                             
                              if(mx == 800){
                              map_created = true;
                                          break;
                                    }
                                   
                              }
                             
                       
                  }
           
      //-----------------------------------------
     //Checks if a menu item has been clickd
     
      public boolean socButton(int y,MouseEvent m){
            boolean clicked;
            if(m.getX() > 650 && m.getX() < 700 && m.getY() > y && m.getY() < y+15){
                  clicked = true;
            } else {
                  clicked = false;
            }
            return clicked;
      }
     
      //-----------------------------------------
     //For futer browser functionality
     public String getAppletInfo() {
            //You can replace this with your own message, but leave SOC Source Written by Ryan Capote
         return "Secrets of Celebrindal V1.0 Written by Ryan Capote. SOC Source V 1.0 Written by Ryan Capote.";
      }
     
      //-----------------------------------------
     //A small function to load the images. Help keeps the code clean
           public void loadImages(){
            //load the images
           grass = getImage(getCodeBase(),"gfx/grass.GIF");
            sprites = getImage(getCodeBase(),"gfx/Sprites.GIF");
            gui1 = getImage(getCodeBase(),"gfx/gui1.gif");
            gui2 = getImage(getCodeBase(),"gfx/gui2.gif");
      }

     
      //-----------------------------------------
     //Initialization
     //-----------------------------------------
     public void init() {
            //do variable stuff
           app_width  = 640;
            app_height = 480;
            tiles_x = 0;
            tiles_y = 0;
            map_x = 32;
            map_y = 32;
            player_y = 64;
            player_x = 64;
            addKeyListener(this);
            addMouseListener(this);
            walk = true;
            walking = false;
            sprite = 198;
           
      }
      //-----------------------------------------
     //When the game starts
     //-----------------------------------------
     public void start() {
           
            //create player
           player = new player();
           
            //create GUI
           gui = new gui();
           
            //Load images
           loadImages();
           
            th = new Thread(this);
            th.start();
           
      }
     
      //------------------------------------------
     //Controles
     //------------------------------------------
     public void keyPressed(KeyEvent e){
            walking = true;
            //Check arrows for character movement - TO BE UPDATED - NEEDS ANIMATION
     if(e.getKeyCode() == keyUp){
            player_y = player_y - 3;
            walk = true;
            dir = 1;
            repaint();
      } else if (e.getKeyCode() == keyDown){
            player_y = player_y + 3;
            walk = true;
            dir = 2;
            repaint();
      } else if (e.getKeyCode() == keyLeft){
            player_x = player_x - 3;
            dir = 3;
            walk = true;
            repaint();
      } else if (e.getKeyCode() == keyRight){
            player_x = player_x + 3;
            dir = 4;
            walk = true;
            repaint();
      }
     
           
      }
     
      public void keyReleased(KeyEvent e){
      if(e.getKeyCode() == keyUp){
            walk = false;

      } else if (e.getKeyCode() == keyDown){
            walk = false;
      } else if (e.getKeyCode() == keyLeft){
            walk = false;
      } else if (e.getKeyCode() == keyRight){
            walk = false;
      }
      }
     
      public void keyTyped(KeyEvent e){
      //      key = e.getKeyChar();
     //      command = command + key;
     }
     
      public void mouseClicked(MouseEvent m){
            //Inventory
           
             if(socButton(455,m) == true){
                   menu_item = 1;
             }
             
             //Equipment
            if(socButton(470,m) == true){
                   menu_item = 2;
             }
             
             //Magic
            if(socButton(485,m) == true){
                   menu_item = 3;
             }
             
             //Stats
            if(socButton(500,m) == true){
                   menu_item = 4;
             }
             
             //Options
            if(socButton(515,m) == true){
                   menu_item = 5;
             }
             
             
      }
     
      public void mousePressed(MouseEvent m){ }
     
      public void mouseReleased(MouseEvent m){ }
     
      public void mouseEntered(MouseEvent m){      }
     
      public void mouseExited(MouseEvent m) { }
     
      //-----------------------------------------
     //game loop
     //-----------------------------------------
     public void run(){
             Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
             
            while(true){
                        repaint();
                 
                 
                  //-----------------------------------------
                  //Checks to see if the user exits the room - BLOCK OF CODE = TEMPORARY
                  //WILL BE USED TO TELEPORT FROM ONE MAP TO ANOTHER
                  //-----------------------------------------
                 if(player_y + 32 > 480){
                        player_y = 0;
                        repaint();
                  }
                 
                  if(player_y < 0) {
                        player_y = 448;
                        repaint();
                  }
                 
                  if(player_x < 0){
                        player_x = 640 - 32;
                        repaint();
                  }
                 
                  if(player_x + 32 > 640){
                        player_x = 0;
                        repaint();
                  }
                  //-----------------------------------------
                 
                                   
                  try{

                  th.sleep(20);

                 
                  } catch(InterruptedException ex){
                       
                  }
           
               
            }
             
      }
     
     
      //-----------------------------------------
     //Buffer, to stop flickering
     //------------------------------------------
     public void update(Graphics g){
     
           
            //create buffer
           if(buffer == null){
                  buffer = createImage(app_width,app_height);
                  bgraphics = buffer.getGraphics();
            }

           
           

           
           
            bgraphics.setColor(getBackground());
            bgraphics.fillRect(0,0,640,480);
           
           
     
            //draw gui
           gui.drawGUI(g,gui1,gui2);
            gui.drawStats(g,25,20,1025,5);
            gui.drawMenu(g);
           
            //Draws the appropiate menu that the user clicked
           switch(menu_item){
                  case 0:
                  //do nothing
                 break;
                                   
                  case 1:
                  gui.drawInventory(g);
                  repaint();
                  break;
                 
                  case 2:
                  gui.drawEquipment(g);
                  break;
                 
                  case 3:
                  gui.drawMagic(g);
                  break;
                 
                  case 4:
                  gui.drawMStats(g);
                  break;
                 
                  case 5:
                  gui.drawOptions(g);
                  break;
            }
           
            paint(bgraphics);

                 
            g.drawImage(buffer,0,0,this);
     
      }
     
      //Draw the Screen
     public void paint(Graphics g){
           

           

           
            //re-draw map + character
                  for(y = 0; y < 480; y = y + 32){
                         bgraphics.drawString("Cirdan",player_x-5,player_y - 15);
                        makeRow(0,y,g);
                        player.drawAvatar(sprites,player_x,player_y,sprite,dir,g);

                  }
           




           
      }
     
           
      //------------------------------------------
     //ending
     //------------------------------------------
     public void stop(){
           
      }
     
      public void destroy() {
           
      }
}
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #16 - Posted 2005-03-25 19:11:47 »

Only exception I got was:

1  
2  
java.lang.NullPointerException
      at SecretsofCelebrindal.paint(SecretsofCelebrindal.java:322)


Line number probably doesn't match up because I had to mod the code to run it locally. Fixed by updating your paint() method to:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
 public void paint(Graphics g){ 
   
 
   if (bgraphics == null) {
         System.out.println("Buffer not enabled yet");
         return;
   }
 
   
  //re-draw map + character
   for(y = 0; y < 480; y = y + 32){
     bgraphics.drawString("Cirdan",player_x-5,player_y - 15);
    makeRow(0,y,g);
 
   }


The paint() method can get called by the AWT event system directly. In this case it gets called before your update() is called and hence the code failed because the "bgraphics" hadn't been initialised yet.

It all ran (once i replaced your gfx references, and pasted in the GUI methods from the last post) swimingly.

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #17 - Posted 2005-03-25 19:18:33 »

Okay, what I did was put the part were it creates the buffer in the paint method, now I don't have the exception anymore.But the gui still doesn't want to work through paint() wich makes it flicker a lot. But drawing the map and the character in the paint() method, flixed that flickering.
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #18 - Posted 2005-03-25 19:25:14 »

I think thats because you're not passing the buffer's graphics context into the drawGUI methods, rather you're passing the real graphics context from the paint() method.

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #19 - Posted 2005-03-25 22:23:03 »

PArden my noobness but, what does that mean? lol
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #20 - Posted 2005-03-26 02:31:30 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
 public void paint(Graphics g){  
   
 
   if (bgraphics == null) {
    System.out.println("Buffer not enabled yet");
    return;
   }
 
   
  //re-draw map + character  
   for(y = 0; y < 480; y = y + 32){  
     bgraphics.drawString("Cirdan",player_x-5,player_y - 15);

   //He means don't do this:
  // makeRow(0,y,g);  
  // but instead do this:
  // makeRow(0,y,bgraphics);
 
   }

   //Finally do this:
  g.drawImage(buffer, 0, 0, null);
}


That's how you use your buffer to remove flickering.  We call that "double buffering".  Maybe I've misunderstood the context of the code, but the idea is the only time you ever call any draw methods on "g" is the last one I put there.  That should be the only time anything gets thrown to the screen.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline Cirdan

Senior Newbie




Java games rock!


« Reply #21 - Posted 2005-03-26 03:50:40 »

the only thin that is flickering is the drawStrings that make up my GUI. thats the only thing that is flickering. The gui doesn't work in the paint method, but it works in the updated method. I'll keep playing with it, and I'll post if I get it.
Online kevglass

JGO Kernel


Medals: 153
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #22 - Posted 2005-03-26 04:17:15 »

Actually I was more worried about these:

1  
2  
3  
gui.drawGUI(g,gui1,gui2); 
  gui.drawStats(g,25,20,1025,5);
  gui.drawMenu(g);


Since they take the normal graphics context as their first parameter instead of the buffered one.

Kev

Offline Cirdan

Senior Newbie




Java games rock!


« Reply #23 - Posted 2005-03-30 03:09:10 »

you can see my flickering problem here...
http://rct3nerds.eblah.com/soc/game/SecretsofCelebrindal.htm
Pages: [1]
  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.

CopyableCougar4 (17 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (38 views)
2014-08-06 19:49:38
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!