Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 13:46:35
Thanks alot got the eclipse thing working Smiley

Also got my code working after i switched to ArrayList<string[]> thanks alot everyone responding quickly Smiley i appriciate all the help.
2  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 12:37:27
Also, a small eclipse problem (for people who use the eclipse IDE), when i type an object E.G: ArrayList.  after the '.' it should show a tool tip like feature with suggestions of possible functions inside that class but since i switched over to ubuntu it doesnt show anymore, anyone know where i can  make it work again (i googled it but i didnt get any results, mainly because i cant think of a decent search query for my problem)
3  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 12:25:09
You have to ask the question: which dimensions will need to be dynamic? You seem to be programming something that is TOO dynamic/flexible if you need an unlimited 2D array and it's not map/level data.
Ye you might be right, iv been trying to make everything as dynamic as possible, maybe im trying to hard and its best to just limit certain things.
4  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 12:20:13
It has only 2 string right now yes, but i'll be expanding it alot in the future, im still in very low stages of my project Tongue

Also, ill just try out ArrayList then, ill edit it if it works
5  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 12:13:32
ArrayList doesnt have multiple dimentions
6  Game Development / Newbie & Debugging Questions / Re: NullPointerException with multi-dimentional array. on: 2011-11-24 12:09:22
But what if i have no limit to how big it can get?

The first array is the character, the array in the array is the character info so a player could have a bunch of diffrent characters. Well ill prob set a limit to it but i still would like to know how i could have an unlimited amount of value's in the array (new String[][] doesnt work Sad )
7  Game Development / Newbie & Debugging Questions / NullPointerException with multi-dimentional array. on: 2011-11-24 11:36:07
Hello everyone,

What im trying to do is that the MySQL class retrieves characters from a certain account id and inserts them into a multi-dimentional array. It does this inside the getCharacters function. But when i insert the values into the multi-dimentional array and run my application it give's a null pointer exception on a certain line. This is the 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  
public String[][] getCharacters(int accId) {
      String[][] characters = null;
      try {
         Statement st = con.createStatement();
         ResultSet rs = st.executeQuery("SELECT * FROM `characters` WHERE `account_id`="+ accId);
         int i = 1;
         while(rs.next()) {
            String username = rs.getString("username");
            int level = rs.getInt("level");
            System.out.println("I: "+ i +" User:"+ username +", Lvl: "+ level);
            characters[i][0] = username;
            characters[i][1] = ""+ level;
            i++;
         }
         rs.close();
         st.close();
         
      } catch (SQLException e) {
         // TODO Auto-generated catch block
        System.out.println("[Login Server][Error]: Error with retrieving characters: "+ e.getMessage());
      } catch (Exception e) {
         System.out.println("");
      }
      return characters;
   }

NullPointerException happens on the following line: "characters[i ][0 ] = username;" (Note there are no spaces between the brackets but the forum views it as BB code)

Iv been stuck with this problem for 4 days now and im sirreusly stressing alot over it, iv asked a few application developers at my school if they could help out but they couldnt find the problem either. I hope someone know's what im doing wrong here and if possible send me a link or type some text informing me on what i did wrong and what i could do to prevent this from happening again..

Thanks in advance Smiley
8  Game Development / Newbie & Debugging Questions / Re: X and Y Coordinate change rate on: 2011-03-22 08:26:23
I got it working properly Smiley.

I made a new Thread with the gameLoop and the thread sleeps after it executes the code. The MS isnt 100% steady, but it only differs 1MS at most unlike the method i used before wich could differ up to 20MS wich is very noticable while your moving
9  Game Development / Newbie & Debugging Questions / Re: X and Y Coordinate change rate on: 2011-03-22 06:49:58
Thanks all of you for your help and explenation, people like you are helping out the next generation of programmers Smiley

I will try to make a loop and make it sleep for 25ms to get me a frame rate of 40.. Ill post later on if this fixed my problem..

One again thx to all of u Smiley
10  Game Development / Newbie & Debugging Questions / Re: X and Y Coordinate change rate on: 2011-03-21 12:19:14
Iv done so and iv got this:
1  
2  
3  
TB: 171677500409656. TA: 171677500411014. Time Diffrence: 1358
TB: 171677504907948. TA: 171677504908854. Time Diffrence: 906
TB: 171677510269938. TA: 171677510270844. Time Diffrence: 906

TB = Time Before
TA = Time After
Time Difference = (TA - TB)
The time is determined with System.nanoTime();

NOTE: The time diffrence changes alot between 300 - 1900

What happens is the loop get's called every 5ms, im using new Timer(5, this) to call the actionPreformed method every 5ms..

So the time diffrence does change, how can i make it constant?

Also: Im using a laptop when i remove my power it slow's down the computer a little. if this happens the whole game get's slower too and i dono why, any idea's?
11  Game Development / Newbie & Debugging Questions / [SOLVED] X and Y Coordinate change rate - THX on: 2011-03-21 10:05:56
Hello everyone,

Im developing a simple 2D game. Iv added movement options for left and right, up is jump. My problem is that the movement refresh rate is 5ms, and it moves 1px, sometimes (random times) the movement slows down as if the refresh rate is 10ms or something. Im not sure how i can debug this to find out why its doing this.

Could someone tell me why this might happen and/or how i can fix this or how i can debug to find why.

If youd like to see for yourself you can download the JAR file HERE.

Right arrow = Move Right
Left arrow = Move Left
Up arrow = Jump
I Key = Inventory open/close
Z Key = Pickup item (Green Boxes)

Thanks very much Smiley
12  Game Development / Newbie & Debugging Questions / 2D Collision Detection on: 2011-03-15 20:30:02
Hey everyone, Im a little new to java and im having a problem with my collision detection.

So let me explain my problem. When a player presses the up key the ingame character (wich is a rectangle atm) increases its Y Coords by 100 and returns to 0 after hitting 100. Iv added some collision detection when comming from the right or left. if the char come's from left -> right it will substract 1 from its X Coords. Same thing when the char come's from right -> left except increasing the X Coords upon collision.

When the char is comming down from the jump his Y coords increases, when he the char collides while comming down it will decrease its y coord by 1 every attempt of moving down. At this point the char is ontop of the rectangle wich it is colliding with and 35pixels above ground level. How can i get the char back down to ground level?

I tried many diffrent ways, one of them was detecting howmany pixels the char was above ground level, and every 5ms making it go down. But the problem with that is that it wont let me go up anymore because it keeps pusing me down, found that out the hard way ^^.

This is my code:

Check collision method: call's the method every 5 ms.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public void checkCollision() {
      Rectangle r = new Rectangle(rx, ry, 50, 50);
     
      if(p.getBounds().intersects(r)) {
         if(p.moveUp == true)
            p.changeY(1);
         if(p.jumping == true)
            p.changeY(-1);
         if(p.moveLeft == true)
            p.changeX(1);
         if(p.moveRight == true)
            p.changeX(-1);
         p.colliding = true;
      } else {
         p.colliding = false;
      }
   }


My character jumping method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void jump() {
      if(jumpMovement < 100 && inJump == true) {
         jumpMovement++;
         changeY(-1);
      } else if(jumpMovement > 0 && inJump == false) {
         jumpMovement--;
         changeY(1);
      } else {
         jumping = false;
      }
      if(jumpMovement == 100) {
         inJump = false;
      }
   }


Thanks in advance Smiley

Also: Im sorry if this isnt enough information but im not really sure how to describe my problem... If anything is unclear do post so, thanks Smiley

[EDIT] While im at it, whats the best way to calculate wich side its colliding on? above, left, right, or from under?
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.

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

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

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

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

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

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

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

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

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

Norakomi (42 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!