Я на самом деле пытаюсь создать pong Game в Android Studio, но у меня есть проблема, которую, я думаю, можно легко решить, но я не знаю как. это мой код: мой класс понг
public class Pong extends View {
//Attributs
private Rect joueur1 = new Rect();
private Rect joueur2 = new Rect();
public Pong(Context ctx){
super(ctx);
}
public void setJoueur1(Rect joueur1) {
this.joueur1 = joueur1;
}
public void setJoueur2(Rect joueur2) {
this.joueur2 = joueur2;
}
@Override
protected void onDraw(Canvas canvas) {
Paint p = new Paint();
p.setColor(Color.WHITE);
canvas.drawRect(joueur1,p);
canvas.drawRect(joueur2,p);
}
}
мой класс Барре
public class Barre {
private Rect hitBox = new Rect();
private int x;
private int y;
private static final int width = 20; //width = longeur
private static final int height =100;
public Barre(int x, int y) {
this.x = x;
this.y = y;
}
public void setHitBox (){
hitBox.set(x,y,width,height);
}
public Rect getHitBox() {
return hitBox;
}
}
мой класс основной
public class MainActivity extends AppCompatActivity {
//Attributs
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Pong pong = new Pong(this);
Barre joueur1 = new Barre(10,0);
Barre joueur2 = new Barre(200,0);
joueur1.setHitBox();
joueur2.setHitBox();
pong.setJoueur1(joueur1.getHitBox());
pong.setJoueur2(joueur2.getHitBox());
pong.setBackgroundColor(Color.BLACK);
setContentView(pong);
}
}
проблема в том, что мой игрок 2 (второй barre) Некоторые важные детали: -Я пытался отладить мое приложение, но все правильно, конструктор получает информацию и устанавливает ее в "joueur1" и "joueur2" - у меня нет ничего в моем XML код - у меня нет последней версии AS, но я думаю, что проблема не в этом - и, между прочим, вы сказали бы мне, если мой код является чистым кодом, СПАСИБО U