We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Collision Detection with multiple classes
Page Index Toggle Pages: 1
Collision Detection with multiple classes (Read 1270 times)
Collision Detection with multiple classes
Feb 16th, 2009, 2:44am
 
I'm trying to get the x and y values of specific objects in another class to be read within a class. However I'm getting this error "The field Component.x is not visible"

here is the snippet of code:

Quote:
class Fclass { // Frog class
  PImage frog;
  float fx;
  float fy;

  Fclass(String fname, float tempfX, float tempfY) {   // Setting frog variables
    frog = loadImage("frog.png");
    fx = tempfX;
    fy = tempfY;
  }

  void display() {                                     // Setting frog display
    image(frog,fx,fy,frog.width,frog.height);
  }

 boolean intersect(CarBR carBlue1) {
    float distance1 = dist(x,carBlue1.x);
    float distance2 = dist(y,carBlue1.y);
    if (distance1 < 51) {
      return true;
    } 
    else {
      return false;
    }
    if (distance2 < 15) {
      return true;
    } 
    else {
      return false;
    }
  }

Re: Collision Detection with multiple classes
Reply #1 - Feb 16th, 2009, 10:34am
 
The problem is probably in the definition of CarBR which we don't see. Perhaps the x field is declared as private.

Note that in intersect, the comparison of distance2 will never be reached, as you always return in distance1 comparison.

Also if you use Processing's dist() function, it needs 4 parameters.
Page Index Toggle Pages: 1