Я пытаюсь создать игру в разделе Обработка. В основном это понг. У меня 3 класса. Основной класс (PongRunner), класс для мяча (PongBall) и класс для ракетки (PongRacket).Как отображать и использовать объект в основном классе обработки
Я пытаюсь показать объект PongRacket в классе PongRunner, но он не отображается. Вот мой код:
Класс PongRacket:
// this is the class for the pong racket used in the game
// it specifies the racket's attributes and methods
public class PongRacket{
// attributes of the pong racket
private int racketWidth = (1/9)*width; // width of the racket
private int racketHeight = (1/15)*height; // height of the racket
private int startRacketXPosition = (4/9)*width; // x value for starting position of racket
private int startRacketYPosition = (14/15)*height; // y value for starting position of racket
// display the racket
public void displayRacket(){
fill(0, 0, 0); // color for racket is black
rect(getStartRacketXPosition(), getStartRacketYPosition(), getRacketWidth(), getRacketHeight());
}
// move the racket
public void moveRacket(){
}
// setters
public void setRacketWidth(int myWidth){
this.racketWidth = myWidth;
}
public void setRacketHeight(int myHeight){
this.racketHeight = myHeight;
}
// getters
public int getRacketWidth(){
return this.racketWidth;
}
public int getRacketHeight(){
return this.racketHeight;
}
public int getStartRacketXPosition(){
return startRacketXPosition;
}
public int getStartRacketYPosition(){
return startRacketYPosition;
}
} // end class PongRacket
PongRunner класс
//this is the main class that runs the game
// it consists of a racket
// why doesn't the racket get displayed?
PongRacket racket = new PongRacket(); // creates the racket object
void setup(){
size(width, height);
frame.setResizable(true); // the frame can be resized now
}
void draw(){
background(255); // color for background is white
racket.displayRacket(); // why isn't this getting displayed?
}
Всякий раз, когда я называю:
racket.displayRacket(); // inside the PongRunner class
Это не работает или отобразить что-либо на экране , Как я могу заставить его работать?
Что ваш вопрос? – ataylor
Извините, мой вопрос не был ясен @ataylor. Я вызываю метод displayRacket() на моем объекте racket из PongRacket внутри моего класса PongRunner, но он не работает или не отображает ничего. Как я могу отобразить его на экране? – stego