I’m using the framework intorduced in the Beginning Android Games book,
It has a method called drawPixmap(), its definition is:
@Override
public void drawPixmap(Pixmap pixmap, int x, int y) {
canvas.drawBitmap(((AndroidPixmap)pixmap).bitmap, x, y, null);
}
When I’m calling the function, let’s say
g.drawPixmap(Assets.ball,200,200);
It works.
but when I use it like this
g.drawPixmap(Assets.ball,ball.getX(),ball.getY());
It doesn’t.
I tried getting the X & Y to a local variable before, still no good.
both X and Y in the ball class are integers.
In the book, he shows a code which includes using variables. but I can’t get this to work.
any ideas why it won’t recognize my cute little variables?
Edit 1:
Now I noticed that in the constructor of that class, it does uses variables successfully.
only in the update() method it doesn’t.
Edit 2:
I get a runtime error:
Fatal Exception Thread-10 java.lang.NullPointerException
at com.carmel.android.accelpong.GameScreen.<init>
But now I thing it’s something with the ball class itself, as even when trying to set the X using the setX() methoed, I get the same error.. but it doesn’t bring me any closer to solving this
Your
ballvariable isnull. You are forgetting to initialize it, or somehow rewritting it. Include the code that goes from ball creation to invoking that function for a more detailed answer.