We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm new to processing This is my code below pls tell me what's wrong with my code
import shiffman.box2d.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
short count, dim = 150;
int num = 0;
PFont counter;
final static short POS = 25, FPS = 50, BOLD = 0;
final static color BG = #C04000,
FG = #82CFD0, BORDER = 0;
PImage photo;
// A reference to our box2d world
Box2DProcessing box2d;
// A list we'll use to track fixed objects
ArrayList<Boundary> boundaries;
// A list for all of our rectangles
ArrayList<CustomShape> polygons;
ArrayList<Ball> balls;
int missed =0;
void setup() {
size(1000,600);
smooth();
counter = createFont("Arial", 72, true);
photo = loadImage("2-01.png");
// Initialize box2d physics and create the world
box2d = new Box2DProcessing(this);
box2d.createWorld();
// We are setting a custom gravity
box2d.setGravity(0, -10);
// Create ArrayLists
balls = new ArrayList<Ball>();
boundaries = new ArrayList<Boundary>();
polygons = new ArrayList<CustomShape>();
// Add a bunch of fixed boundaries
// b1
Boundary b1 = new Boundary(200f, 200f, 150f, 10f, radians(45));
boundaries.add(b1);
// b2
Boundary b2 = new Boundary(500f, 200f, 150f, 10f, radians(-45));
boundaries.add(b2);
Boundary b3 = new Boundary(100f, 200f, 150f, 10f, radians(0));
boundaries.add(b3);
//right side
Boundary rightSide = new Boundary(width-5,height/2,10,height,0);
rightSide.setRotation(-PI/8);
boundaries.add(rightSide);
// left sides
Boundary leftSide = new Boundary(5,height/2,10,height,0);
leftSide.setRotation(PI/8);
boundaries.add(leftSide);
}
{
size(208, 184);
photo = loadImage("2-01.png");
}
void draw() {
background(255);
// We must always step through time!
box2d.step();
image(photo,mouseX,0);
// Display all the boundaries
for (Boundary wall: boundaries) {
//wall.setRotation(PI/6);
wall.display();
}
// Display all the people
{
//for (Ball b: balls)
for (int i=0; i<balls.size(); i++)
{
//important
Ball b = balls.get(i);
b.display();
Vec2 pos = box2d.getBodyPixelCoord(b.body);
if(b.done())
{
missed++;
balls.remove(i);
println("ball missed:"+missed);
createBall();
}
}
}
{
//for (Ball b: balls)
for (int i=0; i<balls.size(); i++)
{
//important
Ball b = balls.get(i);
b.display();
image(photo,mouseX,0);
if(b.done())
{
missed++;
balls.remove(i);
println("ball missed:"+missed);
createBall();
}
}
}
Answers
which line is the null pointer exception on, or are we meant to guess?
we can't run your code because we don't have the images.
or the font.
or any of the libraries.
did you read the FAQ about NPEs? https://forum.processing.org/two/discussion/8071/why-do-i-get-a-nullpointerexception
I'm sry to make u guys confuse haha firs time to use this forum.... now I have add image into here, I'm trying to add the score counter when the image catch the ball will increase the score but not dropping off the window only increase the score...
Which line is the npe on?
( box2d.step();)