Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I draw inside a class? #3

Open
MMPB027 opened this issue Nov 28, 2023 · 2 comments
Open

How do I draw inside a class? #3

MMPB027 opened this issue Nov 28, 2023 · 2 comments

Comments

@MMPB027
Copy link

MMPB027 commented Nov 28, 2023

How do I draw inside a class?

I'm creating a game for a university project and I would like to make a dashed circle indicating the area that the player has to reach to follow the path, however when I use "dashed = new DashedLines(this);" the program says that "The constructor DashedLines(CUBWAY_Ver_4_2.ObstaculoNvl3) is undefined".

I would like to know how I can solve this.

This is the class in question, I would like to know what I have to put in place of "this". Sorry if it's obvious, I'm still learning.

//

DashedLines tracejado;

class ObstaculoNvl3 {

int NdPontas;
float PX0, PY0, PX1, PY1;
int Raio;
float Ang;

float RaioT;

float m = radians(0);

float dist = 0;

ObstaculoNvl3 (int NdP, float X, float Y, int R) {
NdPontas = NdP;

Raio = R;

Ang = radians(360/NdP);

PX0 = X;
PY0 = Y;

RaioT = (Raio*2)/3;

tracejado = new DashedLines(this);
tracejado.pattern(30, 10);

}

void desenhaHorario () {

//Circulo
stroke(148, 56, 173);
strokeWeight(3);
noFill();
tracejado.ellipse(PX0, PY0, RaioT, RaioT);
//circle(PX0, PY0, RaioT);

tracejado.offset(dist);
dist += 1;

//Linha
for (int i = 0; i < NdPontas; i++) {
  PX1 = PX0+(Raio*cos((Ang)*(i+m)));
  PY1 = PY0+(Raio*sin((Ang)*(i+m)));

  strokeWeight(10);
  stroke(0);

  line(PX0, PY0, PX1, PY1);
}
m = m + radians(0.5);

}

void desenhaAntiHorario () {

//Circulo
stroke(148, 56, 173);
strokeWeight(1);
noFill();
tracejado.ellipse(PX0, PY0, RaioT, RaioT);
//circle(PX0, PY0, RaioT);

/*tracejado.offset(dist);
 dist += 1;*/

//Linha
for (int j = 0; j < NdPontas; j++) {
  PX1 = PX0+(Raio*cos((Ang)*(j-m)));
  PY1 = PY0+(Raio*sin((Ang)*(j-m)));

  strokeWeight(10);
  stroke(0);

  line(PX0, PY0, PX1, PY1);
}
m = m + radians(0.5);

}
}

@MMPB027 MMPB027 changed the title I can't make the dashed line move How do I draw inside a class? Nov 28, 2023
@garciadelcastillo
Copy link
Owner

this needs to be a reference to your main PApplet, that is, the main Processing sketch. If you are using dashed lines inside a class, the class needs to have a reference to the PApplet object.

Try changing the constructor to:

ObstaculoNvl3 (PApplet sketch, int NdP, float X, float Y, int R) {
NdPontas = NdP;

Raio = R;

Ang = radians(360/NdP);

PX0 = X;
PY0 = Y;

RaioT = (Raio*2)/3;

tracejado = new DashedLines(sketch);
tracejado.pattern(30, 10);

}

And the, when you construct ObstaculoNvl3 from the main sketch, call it like:

ObstaculoNvl3 obs = new ObstaculoNvl3(this, ...);

@MMPB027
Copy link
Author

MMPB027 commented Nov 28, 2023

Thank you so much, you saved me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants