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 (567)
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  
  LWJGL - Clearing one layer question  (Read 2829 times)
0 Members and 1 Guest are viewing this topic.
Offline Longarmx
« Posted 2012-04-03 04:45:38 »

[size=10pt]Hi again!

So I was continuing on my game made in LWJGL, and I am able to move a player around on a grass background. The only problem I am having is being able to update the player correctly by getting rid of the older player positions.
If i call:

1  
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);


then the grass background disappears and the player updates fine. I can't redraw the grass background every time I update, because the FPS will drop down to about 1 - 3. If there is a way that I can just clear the layer that the player is on, then I would greatly appreciate it.

Thanks,
Longarmx[/size]

Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-04-03 04:53:03 »

I can't redraw the grass background every time I update, because the FPS will drop down to about 1 - 3.

Then you're doing something very wrong in drawing the grass.  You should be able to draw everything visible in every frame and still sustain high framerates.  Maybe if you pasted the relevant rendering code?
Offline Longarmx
« Reply #2 - Posted 2012-04-03 05:09:20 »

[size=10pt]Sorry, I should have given a bit more detail. I am drawing the grass tiles in a nested for loop, and I can't run that 60 times per second.

Longarmx[/size]

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-04-03 05:23:08 »

You should be able to render thousands (if not tens of thousands) of small (e.g. 32x32) tiles easily to the screen every frame.

A) How many tiles are you rendering per frame?
B) How are you drawing the grass tiles?

Show us the code and we can help.

Some ways of speeding up rendering:
- Batch your texture binds. If you are binding a new texture each tile, then you're going to run into performance problems. To minimize texture binds, merge various tiles (grass, wood, dirt, water, etc) into the same "sprite sheet" or texture atlas.
- If you are using immediate mode (glBegin/glEnd), you can speed up tile rendering by calling glBegin only once before your nested loop, and glEnd only once after your loop (assuming all tiles use the same texture and you aren't doing any weird glTranslate/glRotate/etc. in between)
- Learn to write your own vertex array renderer to further speed up sprite rendernig
- If the tiles cover the entire screen, then you don't need to call glClear (assuming you are rendering all tiles every frame). This will speed things up slightly.

Offline theagentd
« Reply #4 - Posted 2012-04-03 06:01:27 »

You should be able to render thousands (if not tens of thousands) of small (e.g. 32x32) tiles easily to the screen every frame.

A) How many tiles are you rendering per frame?
B) How are you drawing the grass tiles?

Show us the code and we can help.

Some ways of speeding up rendering:
- Batch your texture binds. If you are binding a new texture each tile, then you're going to run into performance problems. To minimize texture binds, merge various tiles (grass, wood, dirt, water, etc) into the same "sprite sheet" or texture atlas.
- If you are using immediate mode (glBegin/glEnd), you can speed up tile rendering by calling glBegin only once before your nested loop, and glEnd only once after your loop (assuming all tiles use the same texture and you aren't doing any weird glTranslate/glRotate/etc. in between)
- Learn to write your own vertex array renderer to further speed up sprite rendernig
- If the tiles cover the entire screen, then you don't need to call glClear (assuming you are rendering all tiles every frame). This will speed things up slightly.

Indeed, OP is doing something very wrong. Just take a look at what's possible.

I bet that OP is drawing tiles using glBegin and glEnd. This is insanely slow since your CPU can't feed data fast enough to your GPU. You really need to draw tiles in batches instead of one by one. Since you can't switch textures while drawing tiles you need to have your tiles in a tile map, e.g. a single texture containing all tiles and then pick out tiles using texture coordinates. The easiest way of doing this is with display lists. They're very easy to use. You simply wrap your glBegin/glEnd code in a display list, and then you can draw everything in the display list with a single draw call later without the CPU overhead of glBegin, glEnd, glVertex, e.t.c. Simply doing this should give you perfectly fine performance

I'm not so sure about not calling glClear each frame though. glClear isn't simply a fullscreen quad with a certain color; it's first of all much much faster and secondly might improve performance in other ways. With some pixel modes (mostly multisampled modes) the color/depth/stencil/e.t.c buffers are often compressed to reduce memory usage and more importantly memory bandwidth which can lead to a small performance win. When glClear is called, it resets the compression blocks which is both very and improves performance for subsequent rendering. On a much more advanced level, glClear also signals that frame data will not be reused in multi-GPU setups, which allows the driver to remove the copy between GPUs, but this is of course completely irrelevant in in this case. The point is that the performance cost of glClear is ridiculously low and literally zero if the game is CPU bound, which is OPs case and the case for pretty much every 2D game out there, while there are potential benefits of it. It's better to just make a habit of clearing the screen each frame.

Myomyomyo.
Offline davedes
« Reply #5 - Posted 2012-04-03 06:23:43 »

Quote
The point is that the performance cost of glClear is ridiculously low and literally zero if the game is CPU bound
On my system there is a pretty significant difference. Drawing a single textured quad fit to the display size:
FPS w/o glClear ~ 1000
FPS w/ glClear ~ 770

A more practical example -- in my game (which is drawing hundreds of sprites per frame) it looks more like this:
FPS w/o glClear ~ 650
FPS w/ glClear ~ 490

I suppose the difference isn't huge enough (at this point) to warrant getting rid of glClear, but since I'm not using multi-sampling or depth/stencil buffers I don't see much of a benefit.

Offline theagentd
« Reply #6 - Posted 2012-04-03 07:05:35 »

Quote
The point is that the performance cost of glClear is ridiculously low and literally zero if the game is CPU bound
On my system there is a pretty significant difference. Drawing a single textured quad fit to the display size:
FPS w/o glClear ~ 1000
FPS w/ glClear ~ 770

A more practical example -- in my game (which is drawing hundreds of sprites per frame) it looks more like this:
FPS w/o glClear ~ 650
FPS w/ glClear ~ 490

I suppose the difference isn't huge enough (at this point) to warrant getting rid of glClear, but since I'm not using multi-sampling or depth/stencil buffers I don't see much of a benefit.
You can't afford 0.3 ms? =S

Myomyomyo.
Offline davedes
« Reply #7 - Posted 2012-04-03 07:47:35 »

The difference becomes more pronounced at larger resolutions. At 1920x1080:
Quote
w/o glClear average FPS 99, 12.658228 ms
w/ glClear average FPS 79, 10.10101 ms

Like I said -- I don't see a benefit if I'm not targeting multi-GPU machines or embedded systems.

Offline Danny02
« Reply #8 - Posted 2012-04-03 08:19:08 »

yep pls always use milliseconds instead of FPS to compare performance results d:
Offline theagentd
« Reply #9 - Posted 2012-04-03 09:18:45 »

The difference becomes more pronounced at larger resolutions. At 1920x1080:
Quote
w/o glClear average FPS 99, 12.658228 ms
w/ glClear average FPS 79, 10.10101 ms

Like I said -- I don't see a benefit if I'm not targeting multi-GPU machines or embedded systems.
Whatever. Do what you want. I've said all I've wanted to say. =S

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2012-04-03 09:55:30 »

I'm fairly sure the OP loads the grass image from disk every frame (or every quad). Nothing else will kill your framerate that quickly.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline theagentd
« Reply #11 - Posted 2012-04-03 11:12:54 »

I'm fairly sure the OP loads the grass image from disk every frame (or every quad). Nothing else will kill your framerate that quickly.
I guess that depends on how much grass he's drawing, but now that you mention it it seems very possible.


Myomyomyo.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #12 - Posted 2012-04-03 15:59:29 »

That'd be my guess too.  And that's why we ask for source. Tongue
Offline Longarmx
« Reply #13 - Posted 2012-04-03 20:28:46 »

Ok, here is the source. But before you jump all over me for bad coding, let me just tell you that this is before taking any of your advice.

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  
package com.src.raingame;

import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glEnd;

import java.io.IOException;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class Grid{
   
   private float grassWidth;
   private float grassHeight;
   private float gTexWidth, gTexHeight;

   static Texture grass;
   static Texture player;
   
   
       // * * * * * *
      // All of this is called during initialization
      // * * * * * *

   public Grid(){
     
      // Clearing the screen and the depth
           glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
           
            try{
            grassWidth = grass.getImageWidth();
            grassHeight = grass.getImageHeight();
            }catch(NullPointerException e){
               System.err.println("Getting grass image size failed. Shutting Down...");
               System.exit(1);
            }
           
           
            try{
            gTexWidth = grass.getWidth();
            gTexHeight = grass.getHeight();
            }catch(NullPointerException e){
               System.err.println("Getting grass texture size failed. Shutting Down...");
               System.exit(1);
            }
           
            grass.bind();

            // Drawing the background (grass)
           glBegin(GL_QUADS);
           
                                // So should I just make it into one image and then draw it every time in the main loop?

            for (int i = 0; i < Display.getWidth() / grassWidth; i++) {
               for (int b = 0; b < Display.getHeight() / grassHeight; b++) {
                 
                  GL11.glTexCoord2f(0, 0);
                  GL11.glVertex2f(i * grassWidth,b * grassHeight);
                  GL11.glTexCoord2f(gTexWidth, 0);
                  GL11.glVertex2f(i * grassWidth + grassWidth, b* grassHeight);
                  GL11.glTexCoord2f(gTexWidth, gTexHeight);
                  GL11.glVertex2f(i * grassWidth + grassWidth,b * grassHeight + grassHeight);
                  GL11.glTexCoord2f(0, gTexHeight);
                  GL11.glVertex2f(i * grassWidth,b * grassHeight + grassHeight);

               }

            }
            glEnd();
         
   }
   
   public static void loadGrass(){
      try {
         grass = TextureLoader.getTexture("PNG",
               ResourceLoader.getResourceAsStream("res/grass.png"));
      } catch (IOException e) {
         e.printStackTrace();
         System.err.println("Grass file not found, Shutting down...");
         System.exit(1);
      }
     
     
   }
}


What I want is some way not to clear the loop drawing the grass, and still being able to clear the player images and then draw it in a new position.
Some command that would be nice is: glClear(oldPlayerDrawing);
And then draw the new player.

Thanks,
Longarmx

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #14 - Posted 2012-04-03 20:33:30 »

What I want is some way not to clear the loop drawing the grass, and still being able to clear the player images and then draw it in a new position.

You don't do it like that with OpenGL, you clear your entire screen and re-draw it from scratch. Unless you do something horrifically wrong, this will still be incredibly quick.

Where do you call loadGrass() from? Possibly you could show your whole game loop and what it calls?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Longarmx
« Reply #15 - Posted 2012-04-03 21:02:03 »

Well, I tried rendering the grass every frame and this time it worked without a big fps drop. I don't know why it worked this time but I'm happy. Perhaps I forgot to remove another piece of code when I was testing it before. This is the code I've ended up with:

In the Main Class:

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  
package com.src.raingame;

import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

public class Boot {

   long lastFrame;
   int fps;
   long lastFPS;
   private int playerX, playerY;
   private int playerSpeed;
   
   Player p;
   Grid g;
   
   Texture grass;
   Texture player;

   public static void main(String[] args) {
      new Boot();
   }

   public Boot() {

      boolean running = false;
     
      p = new Player();

      // Creating a new display
     try {
         Display.setDisplayMode(new DisplayMode(800, 600));
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
      }

      // All the initializations
     Grid.loadGrass();
      p.loadPlayer();
      playerSpeed = 100;
      playerX = p.getPlayerX();
      playerY = p.getPlayerY();
      initGL();
      init();
      grass = g.getGrass();
      player = p.getPlayer();
      running = true;

      // Main Loop
     while (running) {
         if (Display.isCloseRequested()) {
            running = false;
         }

          render();

         updateFPS();

         Display.update();
         Display.sync(60);
      }

      // Getting rid of the display
     Display.destroy();
      System.exit(0);
   }


   // Returns the time
  public long getTime() {
      return System.nanoTime() / 1000000;
   }

   // Calculates the delta and then returns it
  public int getDelta() {
      long time = getTime();
      int delta = (int) (time - lastFrame);
      lastFrame = time;
      return delta;
   }

   // Updating the FPS once per second and setting the title
  public void updateFPS() {
      if (getTime() - lastFPS > 1000) {
         Display.setTitle("Some name pre alpha :: FPS: " + fps);
         fps = 0;
         lastFPS += 1000;
      }
      fps++;
   }

   public void init() {
     
      getDelta();
      lastFPS = getTime();
     
      g = new Grid();
     
      p.drawPlayer();
     
   }

   // Initializing the openGL
  public void initGL() {

      GL11.glEnable(GL11.GL_TEXTURE_2D);

      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

      // Enabling alpha blending
     GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

      GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());

      glMatrixMode(GL_MODELVIEW);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
      glMatrixMode(GL_MODELVIEW);

   }

   public void render() {
      glClear(GL_DEPTH_BUFFER_BIT);
     
      grass.bind();
      glBegin(GL_QUADS);
      g.drawGrid();
      glEnd();
     
      checkInput();
     
      player.bind();
      p.updatePlayer();
   }
   
   public void checkInput(){
     
      playerX = p.getPlayerX();
      playerY = p.getPlayerY();
     
      if(Keyboard.next()){
         if(Keyboard.isKeyDown(Keyboard.KEY_A)){
            p.setPlayerX(playerX - playerSpeed);
            System.out.println("A pressed.");
         }
         if(Keyboard.isKeyDown(Keyboard.KEY_W)){
            p.setPlayerY(playerY - playerSpeed);
            System.out.println("W pressed.");
         }
         if(Keyboard.isKeyDown(Keyboard.KEY_S)){
            p.setPlayerY(playerY + playerSpeed);
            System.out.println("S pressed.");
         }
         if(Keyboard.isKeyDown(Keyboard.KEY_D)){
            p.setPlayerX(playerX + playerSpeed);
            System.out.println("D pressed.");
         }
         if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
            System.out.println("Escape key pressed. Shutting Down...");
            System.exit(0);
         }
      }
   }

}


In the Grid Class:

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  
package com.src.raingame;

import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear;

import java.io.IOException;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class Grid{
   
   private float grassWidth;
   private float grassHeight;
   private float gTexWidth, gTexHeight;

   static Texture grass;
   static Texture player;
   
   
   public Grid(){
     
      // Clearing the screen and the depth
           glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
           
            try{
            grassWidth = grass.getImageWidth();
            grassHeight = grass.getImageHeight();
            }catch(NullPointerException e){
               System.err.println("Getting grass image size failed. Shutting Down...");
               System.exit(1);
            }
           
           
            try{
            gTexWidth = grass.getWidth();
            gTexHeight = grass.getHeight();
            }catch(NullPointerException e){
               System.err.println("Getting grass texture size failed. Shutting Down...");
               System.exit(1);
            }
           
            grass.bind();

   }
   
   public static void loadGrass(){
      try {
         grass = TextureLoader.getTexture("PNG",
               ResourceLoader.getResourceAsStream("res/grass.png"));
      } catch (IOException e) {
         e.printStackTrace();
         System.err.println("Grass file not found, Shutting down...");
         System.exit(1);
      }
     
     
   }
   
   public void drawGrid(){
      for (int i = 0; i < Display.getWidth() / grassWidth; i++) {
         for (int b = 0; b < Display.getHeight() / grassHeight; b++) {
           
            GL11.glTexCoord2f(0, 0);
            GL11.glVertex2f(i * grassWidth,b * grassHeight);
            GL11.glTexCoord2f(gTexWidth, 0);
            GL11.glVertex2f(i * grassWidth + grassWidth, b* grassHeight);
            GL11.glTexCoord2f(gTexWidth, gTexHeight);
            GL11.glVertex2f(i * grassWidth + grassWidth,b * grassHeight + grassHeight);
            GL11.glTexCoord2f(0, gTexHeight);
            GL11.glVertex2f(i * grassWidth,b * grassHeight + grassHeight);

         }

      }
   }
   
   public Texture getGrass(){
      return grass;
   }
}


And in the Player Class:

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  
package com.src.raingame;

import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glEnd;

import java.io.IOException;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class Player {
   
   Texture player;
   
   private int playerX;
   private int playerY;
   private float playerWidth, playerHeight, pTexWidth, pTexHeight;
   
   public Player(){
      playerX = 25;
      playerY = 0;
   }
   
   public void loadPlayer(){
      try {
         player = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/player.png"));
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   
   public void drawPlayer(){
      playerWidth = player.getImageWidth();
      playerHeight = player.getImageHeight();
     
      pTexWidth = player.getWidth();
      pTexHeight = player.getHeight();
     
      player.bind();
     
   }
   
   // Updating player position
 
   public void updatePlayer(){
      glBegin(GL_QUADS);
     
      GL11.glTexCoord2f(0, 0);
      GL11.glVertex2f(playerX,playerY);
      GL11.glTexCoord2f(pTexWidth, 0);
      GL11.glVertex2f(playerX + playerWidth, playerY);
      GL11.glTexCoord2f(pTexWidth, pTexHeight);
      GL11.glVertex2f(playerX + playerWidth, playerY + playerHeight);
      GL11.glTexCoord2f(0, pTexHeight);
      GL11.glVertex2f( playerX, playerY + playerHeight);
     
      glEnd();
   }
   
   // Player position
 
   public int getPlayerX() {
      return playerX;
   }

   public void setPlayerX(int playerX) {
      if(playerX <= Display.getWidth() && playerX >= 0){
      this.playerX = playerX;
      }
   }

   public int getPlayerY() {
      return playerY;
   }

   public void setPlayerY(int playerY) {
      if(playerY <= Display.getHeight() - playerHeight && playerY >= 0){
         this.playerY = playerY;
         }
   }
   
   // Player image sizes and texture sizes

   public float getPlayerWidth() {
      return playerWidth;
   }

   public float getPlayerHeight() {
      return playerHeight;
   }

   public float getpTexWidth() {
      return pTexWidth;
   }

   public float getpTexHeight() {
      return pTexHeight;
   }
   
   public Texture getPlayer(){
      return player;
   }

}


I hope I did everything as efficiently as possible. Also, sorry if this is too much code.

Thanks for everything you guys,
Longarmx

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.

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

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

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

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

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

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

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

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

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

BurntPizza (54 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!