Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 37 of 37

Thread: As my player goes lower on-screen my tiles become smaller in height? D:

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    what variable has a null value?

    Which line is line 66? You should not get an error on the call to the System.out.println() method.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I don't see anything wrong in this -_-

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    What is the code on line 66? What you posted doesn't look like it would cause the NPE.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Well, based off context... Your Block class extends Rectangle. Engine.sY is a static variable that should looks like it should never have a null value. Also, in your Block class, when you call y and height, you haven't given any values to those variables. When the code executes, y and height remain null until tick is called.

    I don't know much about Rectangle, but I'm going to guess that x, y, and height are called like this:

    public int x, y, height;
     
    //         OR
     
    public int x;
    public int y;
    public int height;

    You have to give those variables a value to use other wise their value is null. Take a look here: http://docs.oracle.com/javase/6/docs...Rectangle.html
    In tick, what are you trying to print? Also, in this method:

    public void render(Graphics g) {
    		if(id != Tile.air) {
    			g.drawImage(Tile.tileset_terrain, (int)x - (int)Engine.sX, (int)y - (int)Engine.sY, (int)x + width - (int)Engine.sX, (int)y + height - (int)Engine.sY, id[0] * Tile.tileSize - (int)Engine.sX, id[1] * Tile.tileSize - (int)Engine.sY, id[0] * Tile.tileSize + Tile.tileSize, id[1] * Tile.tileSize + Tile.tileSize, null);
    		}
    	}

    Why are you casting x and y as ints ( the (int)x or (int)y ) when they are ints to begin with? render(Graphics g) is going to throw a NullPointerException just like tick.

    --- Update ---

    Quote Originally Posted by Norm View Post
    What is the code on line 66? What you posted doesn't look like it would cause the NPE.
    y and height are causing the NPE because in the Rectangle class, they are initialized without a value. Rectangle (Java Platform SE 6)

  5. #30
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I don't knooowwwwwww D,:

    I am a newb trying to follow a video It all works for him and now this and I don't understand any of it!!!

    The guy said that we need to do that because If we don't it won't work and I tried it and it doesn't and his definition of static was changable and then everyone here says it causes problems and I DON'T GET!

    I just want my block's height to stay the same! :{

    --- Update ---

    I'm a scared lil' newb

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Find in the code where the image is being drawn. Print out the values used by the drawImage method that controls the height of the image. When you find the value/variable that is making the image get shorter, then backtrack in the code to find out why the values of the variables are changing to make the image shorter.

    I don't understand any of it!!!
    The code has no comments describing what it is doing or how the different pieces fit together. Can you ask the author for some documentation for the program that explains what it does?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    My advice, follow a different video. Static means that a variable can be accessed (changing is a form of accessing) by simply evoking the class name.

    //for example
    Math.PI; // is a public static final double value in the Math class that is an approximation of Pi.

    The fact that I couldn't even get the program to run the way you gave is a HUGE red flag. He even got the main method wrong.

    //standard main method
    public static void main(String[] args)
    {
    //code
    }
     
    //his
     
    public static void main(String args[])
    {
    //which doesn't really work because the value would be the ID of the array
    }

    Frankly, if you want to continue with this program, you're going to be frustrated and confused for a long time, at least until you somewhat understand what's going on. Learn the basics of Java then move into GUI's and more advanced algorithms. We will help you if you want to debug this program, the decision is yours.

  8. The Following User Says Thank You to aesguitar For This Useful Post:

    WolfNinja2 (December 23rd, 2012)

  9. #33
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I'm just going to continue with the 2 hour video (As I'm at the last half hour in it) If I find the issue as I go I'll tell you all :/

    --- Update ---

    The reason that there's (int) in front of all those variables is because they're originally double's (unacceptable for drawing things :p )

  10. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    If the video is supposed to be teaching how to program java, its using some poor techniques.
    Most of the static variables could be final. The others should be instance variables.

    The missing documentation in the program is a major fault.
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following User Says Thank You to Norm For This Useful Post:

    WolfNinja2 (December 23rd, 2012)

  12. #35
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    It's just how to do a game. I learn by following these tutorials over and over and eventually I understand it all and pick up some good concepts. But this is just all going to heck I moved on, we added collision but after the player stops, the camera keeps going. But the variable for the camera's Y isn't being messed with anywhere other than where the player's y is. Do not get.

    Stuff like this really down's on my courage to keep up this whole 'Learning Java' :/

  13. #36
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    Don't be discouraged. It takes a long time to learn. There are different ways to learn than through videos. projecteuler.net is a great programming challenge website. Java works well for most of the problem. I've learned a lot about elegant programming, arrays, and math just by solving a few problems. I'm sure there are other websites like it.

  14. #37
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: As my player goes lower on-screen my tiles become smaller in height? D:

    I redid the whole tutorial, WORKS FOR REASONS COMPLETELY UNKNOWN XD

    --- Update ---

    Quote Originally Posted by aesguitar View Post
    Don't be discouraged. It takes a long time to learn. There are different ways to learn than through videos. projecteuler.net is a great programming challenge website. Java works well for most of the problem. I've learned a lot about elegant programming, arrays, and math just by solving a few problems. I'm sure there are other websites like it.
    Thank you

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Drawing many Tiles on screen
    By Gravity Games in forum Object Oriented Programming
    Replies: 12
    Last Post: November 20th, 2012, 08:49 PM
  2. How can i make my Player attack another Player?
    By Graser in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 31st, 2012, 05:01 PM
  3. how to ignore upper and lower case
    By mohamed_saleh2012 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2012, 03:49 PM
  4. java game bullets hit player 1 but not player 2
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 22nd, 2011, 08:19 AM
  5. java game, both players move for player 2 but not player 1
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2011, 12:52 PM