Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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]
1  Java Game APIs & Engines / OpenGL Development / Re: Holding down keys, such as for movement on: 2012-06-16 01:00:58
Simply amazing. Thanks again.
2  Java Game APIs & Engines / OpenGL Development / Re: Holding down keys, such as for movement on: 2012-06-16 00:54:14
I've tried the following, and it still only registers once.

1  
2  
3  
4  
5  
while(Keyboard.next()){
         if(Keyboard.isKeyDown(Keyboard.KEY_W)){
            if(Keyboard.getEventKeyState()){
               setMoving(true,0);
               }

1  
2  
3  
4  
while(Keyboard.next()){
         if(Keyboard.isKeyDown(Keyboard.KEY_W)){
               setMoving(true,0);
         }

1  
2  
3  
4  
5  
6  
while(Keyboard.next()){
         if(Keyboard.getEventKey() == Keyboard.KEY_W){
            if(Keyboard.isKeyDown(Keyboard.KEY_W)){
               setMoving(true,0);
               }
         }


3  Java Game APIs & Engines / OpenGL Development / Holding down keys, such as for movement on: 2012-06-16 00:45:39
1  
2  
3  
4  
5  
6  
while(Keyboard.next()){
         if(Keyboard.getEventKey() == Keyboard.KEY_W){
            if(Keyboard.getEventKeyState()){
               setMoving(true,0);
               }
                         //...etc for A, S, D


This is the code that I use that is supposed to register the key press a single time, and then not anymore. It prevents the action from repeating even if your keys are held down. For an action like movement, however, repeated action from holding down a button is necessary. I have tried screwing around with the code(changing if to while, but that always freezes it up, and removing some of the loops) but none of it is working. What is the code that one needs to allow holding down keys yielding a repeated action?
4  Java Game APIs & Engines / OpenGL Development / Re: Slow down; You're moving too fast! (smooth tile transition problem) on: 2012-06-13 03:05:41
Yo thanks for the help. Yea the problem was that the renderTiles() was doing too much. I separated the part that did the movement into its own method, then put that method into the display while-loop. Thanks for the help, your post was exactly the answer I needed.
5  Java Game APIs & Engines / OpenGL Development / Re: Slow down; You're moving too fast! (smooth tile transition problem) on: 2012-06-12 05:49:40
I'm not sure what to put into display logic and game logic. Here is what I have so far:
---
arranged like this:
1  
//CODE

description of above code
---

1  
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);

This is has got to be display logic...
1  
   p.pollKeys();

It's checking to see if a move has to take place, so game logic...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
      int[] playerPos = p.getPosition();
      int playerX = playerPos[0];
      int playerY = playerPos[1];
     
      while(playerX>=256-16){
         playerX--;
      }
      while(playerX<=16){
         playerX++;
      }
      while(playerY>=256-16){
         playerY--;
      }
      while(playerY<=16){
         playerY++;
      }

This is to prevent it from getting out of the array. It is game logic.

1  
      m.renderTiles(playerX, playerY);

This is actually calling the tiles to be on the screen so it's display.
1  
2  
3  
      updateFPS();

      f.printMsg(-width/2, -height/2, "FPS : " + Integer.toString(thisFPS));

Game, I guess. It's not like it has to do with getting something on screen.
EDIT: Maybe updateFPS() is game logic and f.printMsg is display logic?
1  
         Display.update();

I assume this is the equivalent of the render() at the end...

Anyway, when I arrange it like how it is above, it becomes black most of the time and occasionally flashes with what's supposed to be on the screen. Sure, it doubles my framerate, but the actual map only appears intermittently. Furthermore, it doesn't even seem like it's playing the animation.

I don't know, it just seems kind of subjective which is which.
6  Java Game APIs & Engines / OpenGL Development / Re: Slow down; You're moving too fast! (smooth tile transition problem) on: 2012-06-11 04:31:57
Is that the solution to my problem? The delta value? I don't get how it helps.

Right now my game loop is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
while(!Display.isCloseRequested()){
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT);
    //Poll player's keys
   //get player's current position
   //render the tiles based off of the position(it only renders tiles near the player)
   //update FPS
   //print FPS
   //update display
}


Where do I put this 'update cycle', and which part is being cycled? The link you posted didn't talk about update cycles.
7  Java Game APIs & Engines / OpenGL Development / Re: Slow down; You're moving too fast! (smooth tile transition problem) on: 2012-06-10 05:57:37
Perhaps add a 'graphics' update along with your 'logic' update to your code.

I'm not sure how you're managing your game loop currently, but a normal thing is to define a number of 'update cycles' that should happen per second, and only update that number of times rather than allowing your game to update every time you paint things. In a way, this will increase your FPS (Because a lot of the time, you'll be skipping your update step and just painting) and if your game is played on a platform that is slower for whatever reason you'll have more consistent game play.

Instead of having this shift in your render code, you should put it into your logic code, or into another method that is called at some specific rate to ensure that it's only updated X times per second. Whether this falls into a real 'logic' update or into a secondary sort of 'graphics' update function is up to you.

Someone else might be able to give you a better idea of how to do it take a peek at: http://www.java-gaming.org/topics/game-loops/24220/view.html if you haven't.

See yea, I read that thread before and set up a 'variable timestep'. The problem is, that's one of the things I read where I was just blindly following what it said. I don't actually understand it, but I've had this 'delta' variable for a long time and I don't even know what to do with it. Is that how I fix the problem?
8  Java Game APIs & Engines / OpenGL Development / Slow down; You're moving too fast! (smooth tile transition problem) on: 2012-06-09 06:40:54
The game I am creating is tile-based. Movement is per-tile, as one would expect a tile-based game to be. This means that the player presses to go left once, the character automatically moves to the left the space of a single tile.

I decided that it jumping from tile to tile just didn't look professional enough(http://glasszee.tumblr.com/post/24288781615/camera-movement-is-still-choppy-moving-one-tile), so I added a certain thing that moved the camera to the left bit by bit. Say the distance between a tile was 32 pixels. What it does in the video is go straight from 0 to -32. But I changed it so that you press left, and the x coordinate will go 0, -1, -2, -3, -4, -5, -6, all the way to -32. I printed the x coordinate out, and it's apparently working. The problem is that it's moving so fast that you can't even comprehend that it's moving. Which isn't surprising-- at 200 frames per second, the difference between 2 frames and 32 frames won't seem like that much.

How do I slow down the time between the 0, -1, -2, -3, etc? Maybe OpenGL has a way for it to wait a certain amount of time before going to the next frame, while not stopping other areas of the code?

EDIT: Here is some relevant code that you may want to see.
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  
if(isMoving){
      while(x == 0){  
         switch(direction){
         case 0: desiredY=yAdd+(scale*s);//scale*s is the length of a tile
        break;
         case 1: desiredX=xAdd+(scale*s);
         break;
         case 2: desiredY=yAdd-(scale*s);
         break;
         case 3: desiredX=xAdd-(scale*s);
         break;
         }
         x = 1;/*this wonky thing is to have this happen once every 'isMoving' occasion,
                       or else the desiredX or Y will always be (scale*s) more extreme than xAdd and it'll go on forever.*/

      }
   }      
         if(xAdd<desiredX){ /*the reason it's not a 'while' is because, to my understanding, it only renders when it reaches
                                                    Display.update(). A 'while' would have it move to -32 before updating even once.*/

            xAdd+=1;
         } else if(xAdd>desiredX){
            xAdd-=1;
         } else if(yAdd<desiredY){
            yAdd+=1;
         } else if(yAdd>desiredY){
            yAdd-=1;
         } else {
            isMoving=false;
            x = 0; //now it's not moving anymore, so everything resets.

//glBindTexture, glBegin, etc.
        }
9  Game Development / Game Play & Game Design / Good 8-bit music synthesizer? on: 2012-04-13 03:13:58
What synthesizers do you guys use for your games? I don't need anything complicated really, but I'd love to see the different software that you use, as well as if you think it's any good.
10  Game Development / Game Mechanics / Re: What exactly defines an entity? on: 2012-03-29 04:29:35
So it's a general thing, without much of a stone-set definition. Besides a draw function, and its position in the screen, what else does the entity superclass need in it? Not all the entities will move, so you can't have moving functions, and health/stamina seem too specific too. What else could you possibly put in there that defines every single 'something' in the game?
11  Game Development / Game Mechanics / What exactly defines an entity? on: 2012-03-29 01:11:04
What makes an entity an entity, what special features does it have? What do entities do?

EDIT: entity as in the ones commonly used in games for a superclass(i think thats the right term)
12  Java Game APIs & Engines / OpenGL Development / Re: glTexCoord for images with many tiles? on: 2012-03-26 19:18:55
Thank you; looks like I'm on the right track then. Getting it to calculate all that automatically sounds like a good(and necessary) step from here, I'll try to work that out next.
13  Java Game APIs & Engines / OpenGL Development / glTexCoord for images with many tiles? on: 2012-03-26 17:45:37
Take a look at this image

http://i.imgur.com/9EdMG.png

It's a 78*24 image of the alphabet, with each letter in a 6*6, so 52 total squares.

Wouldn't using glTexCoord to get a single letter out of that image get kind of tedious?

      GL11.glTexCoord2f(0,0);
      
      GL11.glTexCoord2f(1/13,0);
      
      GL11.glTexCoord2f(1/13,1/4);
      
      GL11.glTexCoord2f(0,1/4);

Since 1/13 of 78 is 6 and 1/4 of 24 is 6, is this kind of what I'm looking to do, to single out a letter? I'm just making sure this is the way to go. Thanks

EDIT: The 1/13 and 1/4 would be decimals in the actual code so that it would actually work, this is just so that it'll read easier(just like the glVertex3f isn't there)
14  Java Game APIs & Engines / OpenGL Development / What does this code in a textureloader do? on: 2012-03-26 03:10:50
1  
2  
3  
4  
5  
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);


I saw this code being used after a texture ID was generated and bound, and before the texture ID is returned to where it'll be rendered. Whatever it is, it works, and the texture doesn't show without it. Can someone please explain what it means? I'd rather not use it without knowing what it actually is.
15  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-03-02 21:45:07
Gee, I couldn't have done it without your great help! Thanks.
16  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-03-02 18:31:24
The iteration as in every time it repeats the 'for' loop. With the for loops how they are, wouldn't it just run through it diagonally like you said?

1  
2  
3  
4  
5  
6  
    for(int y = 0; y < image.getHeight(); y++){
        for(int x = 0; x < image.getWidth(); x++){
            int pixel = pixels[y * image.getWidth() + x];
               ...
        }
    }


Ah, nevermind! It doesn't repeat each 'for' loop every time. Instead of what I posted earlier, if w is 4 and h is 7...

0 * 4 + 0 = 0,
0 * 4 + 1 = 1,
0 * 4 + 2 = 2,
0 * 4 + 3 = 3,
THEN the second for loop would end and the first one would iterate with y = 1 and the second one restarts,
1 * 4 + 0 = 4,
1 * 4 + 1 = 5,
1 * 4 + 2 = 6,
1 * 4 + 3 = 7,
Then the second loop ends again, and whatever. It keeps going.

Anyway, I thought that both 'for' loops repeated every single time, which wouldn't make any sense. Thanks for clearing that up, lol.

EDIT: I think I explained that kind of awkwardly. <___<;; heh, ah well.
17  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-03-02 18:03:56
I apologize, it seems like each of your responses are making me ask even more questions. I'm learning a whole lot, though, so thank you again.

Quote from: ra4king
The pixels array holds pixels in a 1D array, meaning every WIDTH number of indices is 1 scanline, or 1 row of pixels.
1  
pixels[y * image.getWidth() + x]

That gets the pixel at (x,y) by finding the Y'th row and then X'th pixel on that row.

If getWidth and getHeight return 4 for the example,
on the first iteration it would be 0*4 + 0, so it would get the 0th int in the pixels array.
on the second iteration it would be 1*4 + 1, so it would get the 5th int in the pixels array.
on the third iteration it would be 2*4 + 2, so it would get the 10th int in the pixels array.
on the fourth iteration it would be 3*4 + 3, so it would get the 15th int in the pixels array.
Then y wouldn't be less than width anymore so it would stop.

Maybe it's because I don't understand 1D arrays, but the array was defined with getWidth * getHeight amount of numbers in it, which would be 16. But only the 0th, 5th, 10th, and 15th of them are being used? What about 1-4, 6-9, 11-14?

Quote from: ra4king
0xFF - this is hex for 255, aka 1 byte: 11111111. I advise you learn the hexadecimal system Smiley

I went and did just that. Also I found out that the 0x was just the prefix used for hex.

Quote from: ra4king
& - that is the AND command. This takes 2 values and outputs an AND'ed value. Basically, it tests each bit in the first value against each bit in the same position in the second value. Both bits have to be 1 to get a 1, otherwise you get 0. For example:
1  
2  
3  
int v1 = 18;       //0001010
int v2 = 20;       //0001100
int o = v1 & v2;   //0001000

There is also the OR command using | : int o = v1 | v2; This tests for at least 1 of the 2 bits to be a 1 to get a 1.
And lastly there is the XOR command using ^ : int o = v1 ^ v2; This tests for at MOST 1 of the 2 bits to be a 1 to get a 1. If both are 1 or 0 then you get 0.

Alright, I think I see what you mean. Using OR in the example you posted would get 0001110, and using XOR would get 0000110.

Quote from: ra4king
V >> X - this is the right bit shift command. This shifts all the bits in value V to the right X number of times. For example:
1  
2  
byte v = 54;     //00110110 in binary
byte u = v >> 2; //00001101 = value of 13


Since an int is made up of 4 bytes and each color component is 1 byte, you want to separate out those 4 bytes into 4 separate variables.
The first line shifts the bits to the right 16 times to put the 2nd byte from the left in the rightmost byte position and makes sure only those rightmost 8 bits are left by doing "& 0xFF".
Second line gets the 3rd byte from the left.
Third line just gets the rightmost byte.
Fourth line gets the leftmost byte.

Oh I get it. It's stored like AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB, so moving it to the right 16 times would make it AAAAAAAARRRRRRRR, right? And the reason that RRRRRRRR remains and not AAAAAAAARRRRRRRR, is because you 'AND' 'd 0xFF, which is 0000000011111111(which, when and'd with something, would make it only use the last 8. )?
18  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-03-02 04:30:59
Thank you for your help, ra4king.

I didn't know that ByteBuffers were arrays. I looked back at the link that Stranger posted and compared it to a resource and I think I've got some of it. Looking at the loadTexture method, I now understand it up to the for-loop.

I don't understand how the for loop works.

1  
2  
3  
4  
5  
6  
7  
8  
    for(int y = 0; y < image.getHeight(); y++){
        for(int x = 0; x < image.getWidth(); x++){
            int pixel = pixels[y * image.getWidth() + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF));     // Red component
           buffer.put((byte) ((pixel >> 8) & 0xFF));      // Green component
           buffer.put((byte) (pixel & 0xFF));               // Blue component
           buffer.put((byte) ((pixel >> 24) & 0xFF));    // Alpha component. Only for RGBA
           }

I've never heard of some of these things in this loop before. Anyone care to explain it like I'm five? Thank you everybody for your help so far.
Just to show that I'm actually trying to comprehend this and not sitting back and letting you all to do the work, I'll type what I understand in the loop below.

Say getWidth and getHeight both return 16. The first two lines make x and y go from 0 to 16 in every iteration. The third line is sort of confusing. I think pixel is equal to the certain spot for a pixel in the array that was created earlier? I don't know how "[y * image.getWidth() + x]" does that though. Then the next 4 lines are just putting data into that pixel? "((byte) ((pixel >> 16) & 0xFF))" is really a piece for me. The reference I was looking at had a ton of different parameter options for put(), and I can't figure out which one is being used here, so I don't know what's happening in there. I've seen 0xFF in a book I read a few weeks back but the 0xFF was the reason I put the book down, I have no idea what it is. I don't know if this is making zero sense at all, I have no idea what's going on in the bottom 5 lines, just a vague idea not based on the code itself but on context clues.
19  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-03-01 01:30:25
Thank you for typing that. So if images are made of length, width, and the color components, you just transfer that info from the bufferedimage to the bytebuffer and you're done?

I actually don't know the difference between a bufferedimage and a bytebuffer, other than OpenGL needs bytebuffers and can't use bufferedimage. Are there any complications to transfering the length, width, and RGBA?
20  Java Game APIs & Engines / OpenGL Development / Re: In-depth explanation of bufferedimage to bytebuffer? on: 2012-02-29 01:47:45
Thanks for the responses guys,


That's one of the pre-made ones I was talking about. I suppose I can try to look deeper into it.

You are not wrong, although you are focusing too much on the code. You should start by investigating the wonderful world of images, computer monitors and pixels and how a BufferedImage stores them. Pixel formats, bit depths, alpha channels, scanlines, all that jazz.

Sounds like a good idea. Are there any references or java wiki pages that have something like that I could read, or is it not that straightforward?
21  Java Game APIs & Engines / OpenGL Development / In-depth explanation of bufferedimage to bytebuffer? on: 2012-02-28 02:01:46
Since bytebuffers are what opengl uses, and I am needing this for opengl, I figured I'd post here. I've seen many pre-made texture loaders and things that convert from bufferedimage to bytebuffer that I could use, but I they're kind of daunting. What are the absolute basics for what you need changing a bufferedimage to bytebuffer?

For starters, what information does the bytebuffer need to get from bufferedimage and how is it gotten? I know this is a difficult question, sorry. To really understand the question, I feel like starting from the basics would be best.
22  Java Game APIs & Engines / OpenGL Development / Re: 2D - Restricted to appying sprite textures to shapes? on: 2012-02-26 16:43:52
Thanks, that looks like a good place to start.  Do you know where I can find a tutorial on how to add the TextureLoader to my project? Is it like a library?

Yes, by implementing your own texture Loader Smiley

But how? What would I use to get the PNG file into something I can code with? Wouldn't using bufferedimage or awt would be kind of counter-intuitive, since I'm using LWJGL anyway? I don't know what to use to get the image, is there some sort of way to do it in LWJGL or OpenGL?
23  Java Game APIs & Engines / OpenGL Development / Re: 2D - Restricted to appying sprite textures to shapes? on: 2012-02-25 23:01:56
He's loading the textures with Slick? Isn't there a way to do that with just LWJGL without Slick2D
24  Java Game APIs & Engines / OpenGL Development / 2D - Restricted to appying sprite textures to shapes? on: 2012-02-24 04:59:16
In LWJGL, the only way to go about getting a sprite on the screen is applying the texture to a shape, then showing the shape on the screen? Is there any way to just cut out the middleman and get the sprite on the screen? Just seems sort of strange, you have to worry about getting the actual proportions of the texture equal to the shape and everything.

Also, since the sprite is usually small(32 by 32 pixels or so), how do you make it so that it doesn't appear small on the screen? Changing glOrtho wouldn't change the size of the pixels I don't think, just make the area you can view the pixels smaller on the screen.

Please correct me if any of the information above is incorrect or strange, I'm not quite familiar with some of these ideas.
25  Java Game APIs & Engines / OpenGL Development / Re: Good for 2D game development? on: 2012-02-21 22:44:28
Alright, sounds good. I'll look into LibGDX too.
26  Java Game APIs & Engines / OpenGL Development / Good for 2D game development? on: 2012-02-21 22:18:47
Would LWJGL be any good for 2D games(without using Slick), I know that it's used for 3D games mostly. I ask this because I got sort of familiar with how it works over some amount of time and want to try and make a 2D game. Would I be better off using something like Java's default libraries with BufferedImage and AWT.
27  Java Game APIs & Engines / Java 2D / Re: Types of 2.5D on: 2012-02-21 21:29:56
So I guess it turns out the definition 2.5D isn't as set in stone as I previously thought. I was thinking on the lines of what what ReBirth said.

@tberthel, I'd love to understand what you mean but I'm slightly confused. What are 2D posters? Sorry for my inexperience.
28  Java Game APIs & Engines / Java 2D / Types of 2.5D on: 2012-02-21 04:30:59
I've been looking at threads about 2.5D, most of them talk about a first-person view 2.5D like Doom and Prelude of the Chambered. What is the type that shows you a view of the world at an angle(EDIT: like a flat plane of the world), What makes it 2.5D and not 3D? Popular examples of games that use it would be nice. One other thing, what constraints do you have in 2.5D as far as camera angles and camera-movement goes(swiveling the camera view from side to side, and something like this http://i.imgur.com/L8rw9.png)?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (14 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

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

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

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

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

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

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

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

BurntPizza (48 views)
2014-08-09 21:09:32
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!