O aplicativo executa, mas a bola vermelha(passaro) não aparece. Segue as classes Main Activity, Game, Passaro e Cores respectivamente.
public class MainActivity extends Activity {
private Game game;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout container = findViewById(R.id.container);
game = new Game(this);
container.addView(game);
}
@Override
protected void onResume() {
super.onResume();
game.inicia();
new Thread(game);
}
@Override
protected void onRestart() {
super.onRestart();
game.pausa();
}
}
public class Game extends SurfaceView implements Runnable{
private boolean isRunning;
private SurfaceHolder holder = getHolder();
private Passaro passaro;
private Canvas canvas;
public Game(Context context) {
super(context);
inicializaElementos();
}
private void inicializaElementos() {
this.passaro = new Passaro();
}
@Override
public void run() {
while (isRunning){
if (!holder.getSurface().isValid())continue;
canvas = holder.lockCanvas();
passaro.desenhaNo(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
public void inicia() {
isRunning = true;
}
public void pausa() {
isRunning = false;
}
}
public class Passaro {
private static final float X = 100;
private static final float raio = 50;
private static final Paint color = Cores.getCorDoPassaro();
private float altura;
public Passaro(){
altura = 100;
}
public void desenhaNo(Canvas canvas) {
canvas.drawCircle(X,altura,raio,color);
}
}
public class Cores {
public static Paint getCorDoPassaro(){
Paint paint = new Paint();
paint.setColor(0xFFFF0000);
return paint;
}
}