The constructor is undefinded .. how can I solve it?

edited June 2017 in Library Questions

Hey!

I'm trying to make a game for my programming class and I want to use the AI for 2D Games library. I'm working at the guide at the moment and copied some code from the page, but unfortunately i get this error message: "The constructor BitmapPic(AnimRenderer_01, String, int, int, int) is undefinded"

That's the code I'm using: (the problem is in line 33)

import game2dai.*;
import game2dai.entities.*;
import game2dai.entityshapes.*;
import game2dai.entityshapes.ps.*;
import game2dai.fsm.*;
import game2dai.graph.*;
import game2dai.maths.*;
import game2dai.steering.*;
import game2dai.utils.*;

// AnimRenderer_01
World world;
StopWatch sw;
Vehicle tank;
Vector2D target = new Vector2D();
BitmapPic view;

public void setup() {
  size(600, 320);
  world = new World(width, height);
  sw = new StopWatch();
  // Create the mover
  tank = new Vehicle(new Vector2D(width/2, height/2), // position
    40,                 // collision radius
    new Vector2D(0, 0), // velocity
    40,                 // maximum speed
    new Vector2D(1, 0), // heading
    15,                 // mass
    1.5f,               // turning rate
    1000                // max force
  ); 
  // What does this mover look like
  view = new BitmapPic(this, "tanks.png", 8, 1, 0);    
  view.showHints(Hints.HINT_COLLISION | Hints.HINT_HEADING | Hints.HINT_VELOCITY);
  tank.renderer(view);
  // Finally we want to add this to our game domain
  world.add(tank);
  sw.reset();
}

public void draw() {
  double elapsedTime = sw.getElapsedTime();
  target.set(mouseX, mouseY);
  tank.AP().arriveOn(target);
  float speed = (float) tank.speed();
  float maxSpeed = (float) tank.maxSpeed();    
  if (speed > 1) {
    float newInterval = map(speed, 0, maxSpeed, 0.6, 0.04);
    view.setAnimation(newInterval, 1);
  }
  else {
    view.pauseAnimation();
  }
  world.update(elapsedTime);
  background(218, 140, 54);
  world.draw(elapsedTime);
}

I'm using Processing 3.3.4 and AI for 2D Games 1.1,

I really hope someone can help me!

Best Regards from Germany!

Answers

  • Answer ✓

    You get the error because the constructor doesn't exist. The most common cause of this error is incorrect parameters - either incorrect number and/or types. In this case I suspect that line 33 should be

    view = new BitmapPic(this, "tanks.png", 8, 1);

    and for some reason you have an extra parameter , 0.

  • @quark Thank you very much! It works perfectly without the 0.

  • I thought that might fix it. You can always have a look the the API, this page shows details of the BitmapPic class

  • ah, I see. But after the API there should be a thrid number, or? A number for the interval

  • Well spotted. =D>

    This is a mistake in the documentation rather than the source code. I have corrected the online API to remove the superfluous parameter.

Sign In or Register to comment.