0
더 이상 답변 할 필요가 없습니다.캔버스 애니메이션 업데이트
앱을 만들었으며 화면 주위에 거품이 튀어 나와야합니다. 모든 것이 작동하지만 라이브로 그려지지 않습니다. 여기
코드 (모든 코드,하지만 중요한 코드) :
버블 클래스 :
public class Bubble{
private int ID;
private float coordX;
private float coordY;
private float velX;
private float velY;
private float radius;
private int color;
private boolean popped;
private boolean alive;
private boolean dead;
public Bubble(int coordX, int coordY, int velocityX, int velocityY, int ID, int color) {
this.coordX = coordX;
this.coordY = coordY;
this.velX = velocityX;
this.velY = velocityY;
this.radius = 30;
this.ID = ID;
this.color = color;
this.alive = true;
}
public void drawMe(Paint paint, Canvas canvas) {
int paintStartColor = paint.getColor();
paint.setColor(this.color);
canvas.drawCircle(this.coordX, this.coordY, radius, paint);
paint.setColor(paintStartColor);
Log.d("Bubble","drawn bubble [" + ID + "] at (" + this.coordX + "|" + this.coordY + ")");
}
public void update() {
//damit die bubble am rand anstößt und zurück prallt
if(this.coordX - this.radius <= 0) this.velX = - this.velX;
if(this.coordY - this.radius <= 0) this.velY = - this.velY;
if(this.coordX + this.radius >= MainActivity.getInstance().getScreenSize().x) this.velX = - this.velX;
if(this.coordY + this.radius >= MainActivity.getInstance().getScreenSize().y) this.velY = - this.velY;
coordX += velX;
coordY += velY;
updateRadius();
// Log.d("Bubble", "CoordX: " + coordX + ", velX: " + velX);
}
}
그리기 방법 :
public void drawBubbles() {
Paint paint = new Paint();
for(Bubble b : bubbles) {
b.drawMe(paint, MainActivity.getInstance().getCanvas());
}
}
그리고 게임 루프 :
while(this.isRunning()) {
updateBubbles(); //update bubbles just calls the update() function in every bubble (for each loop)
drawBubbles();
//...sleep...
}
모든 거품을 그리기 위해, 그리고 그것은 작동하지만, 나는 (닫지 않을!) 응용 프로그램을 떠날 때 그 차이를 볼 수 있습니다. 루프에서 메서드를 호출하면 초당 60 번 호출되지만 화면에 나타나지 않는 이유는 무엇입니까? 또한 캔버스를 무효화 할 수 없습니다.
좋아요. 버블 클래스와 게임 루프를 추가했는데, 충분하다고 생각합니다. 더 많은 코드가 필요하면 알려주세요. – Finni