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.
Re: As my player goes lower on-screen my tiles become smaller in height? D:
I don't see anything wrong in this -_-
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.
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:
Code java:
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:
Code java:
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
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)
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
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.
Quote:
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?
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.
Code java:
//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.
Code java:
//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.
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 )
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.
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\' :/
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.
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
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 :)