Why cannot find a class or type named "Box"

import shiffman.box2d.*;

ArrayList<Box>boxes;
PBox2D box2d;

void setup(){
  size(400,300);
  boxes = new ArrayList<Box>();
  box2d = new PBox2D(this);
  box2d.createWorld();
}

void draw(){
  box2d.step();
  background(255);
  if(mousePressed){
    Box p = new Box(mouseX,mouseY);
    boxes.add(p);
  }
  for(Box b:boxes){
    b.display();
  }
}

class Box{
  Body body;
  float w,h;
  
  Box(){
    w=16;
    h=16;
   
  BodyDef bd = new BodyDes();
  bd.type = BodyType.DYNAMIC;
  bd.position.set(box2d.coordPixelsToWorld(mouseX,mouseY));
  body = box2d.createBody(bd);
  
  PolygonShape ps = new PolygonShape();
  
  float box2dw = box2d.scalarPixelsToWorld(w/2);
  float box2dh = box2d.scalarPixelsToWorld(h/2);
  
  ps.setAsBox(box2dw,box2dh);
  
  FixtureDef fd = new FixtureDef();
  fd.shape = ps;
  fd.density = 1;
  fd.friction = 0.3;
  fd.restitution = 0.5;
  body.createFixture(fd);
 }

  
  void display(){
    Vec2 pos = box2d.getBodyPixelCoord(body);
    float a = body.getAngle();
    pushMatrix();
    translate(pos.x,pos.y);
    rotate(-a);
    fill(175);
    stroke(0);
    rectMode(CENTER);
    rect(0,0,w,h);
    popMatrix();
}

void killBody(){
  box2d.destroyBody(body);
}
}

You define constructor without parameters, but you use constructor new Box(mouseX,mouseY) two parameters. That causes the error.

2 Likes