How can I access a variable from my class?

I'm not sure if I've worded this question correctly, but I'm trying to get my player to move with the keyCode on the keyboards using if statements. My problem is that I can't figure out how to access a variable from my class. Here's the parts of the code that are affected!

There's more the this code, as it's in gameStates and all that jazz, but so if the whole code is needed in order to fix let me know, I'll post upon request.

int q = 0;

void setup(){

}

void draw(){

if (keyPressed && (key == CODED)) { if (keyCode == RIGHT){ q += 4;} else if (keyCode == LEFT){ q += -4;
} player.display( ); //THIS IS WHERE I'M HAVING THE ISSUES. } }

class Player {

int a = 55; int b = 60;

float x; float y; float radius; // the radius of the character for collision purposes int frame; // animation frame index int flip; // indicates where the player is facing

// Constructor Player() { frame = 0; }

//radius = 25; //flip = 1;

void display(int posx, int posy) { int posX = posx; int posY = posy; pushMatrix(); translate(posX, posY); scale(flip, 1); image(playerFrames[frame], 0, 0); popMatrix();

if (frameCount % 5 == 0) frame ++;  // animate
if (frame >= playerFrames.length) frame = 0; // loop

}

void move() { x = mouseX; y = mouseY; if (mouseX > pmouseX) flip =1; //if (mouseX < pmouseX) flip =-1; } }

PS this is fairly urgent so if anyone has suggestion let me know!

Tagged:

Answers

  • Edit post, highlight code, press Ctrl-o to format.

    Where is player defined? Not the class, the instance.

  • Answer ✓

    player.display() takes two arguments but it looks like you are passing none.

    //THIS IS WHERE I'M HAVING THE ISSUES.

    The complete error message is useful here, not just 'i have an error'

  • I got it fixed actually !Thanks for your help!

Sign In or Register to comment.