Class is unable to access screen
in
Programming Questions
•
1 year ago
I have a class which is supposed to draw a player on the main screen. For some reason the class wasn't drawing anything. Using the println() command I narrowed the problem down the line that draws the first shape, a circle.
Is there a special way for classes to access the main part of a sketch? I'm new to OOP, so any tips are appreciated.
Here is my main sketch:
- /*
- Ben Cracknell
- January 30, 2012
- */
- /****************************************************************************
- **********************************MAIN LOOP**********************************
- ****************************************************************************/
- //user editable variables
- //player
- //system variables
- //player
- Player myPlayer; //create var for player class
- void setup() {
- size(800,600);
- smooth();
- initPlayer(); //initilize player
- }
- void draw() {
- background(20); //redraw background every frame, to erase previous frames
- }
- /****************************************************************************
- **********************************FUNCTIONS**********************************
- ****************************************************************************/
- //this function innitilizes the player
- void initPlayer() {
- myPlayer = new Player(width / 2, height / 2); //load player object
- }
Here is the class file:
- class Player {
- //user editable variables
- //player
- int playerSize = 40; //height and width of player in px
- Player(int dx, int dy) { //dx and dy will be the player's location
- //base colors
- stroke(120);
- fill(255);
- //base
- ellipseMode(CENTER);
- ellipse(dx,dy,playerSize,playerSize); //draw ball *****Problem on this line*****
- }
- }
1