I'm developing an android game, and my screen is not displaying what I want it to. I've read various tutorials but they are either outdated or hard to follow. I have followed this tutorial and most of the code is identical. However, when running the game, the screen is black.
Game logic loop:
public void run(){
while(running){
long beforeTime = System.nanoTime();
gameEngine.update();
Canvas c = null;
try{
c = holder.lockCanvas(null);
//synchronized (holder){
c.drawRect(0,0,c.getWidth(),c.getHeight(),blackPaint);
gameEngine.draw(c);
//}
}finally{
if(c!=null){
holder.unlockCanvasAndPost(c);
}
}
this.sleepTime = delay-((System.nanoTime()-beforeTime)/1000000L);
try{
if(sleepTime>0){
this.sleep(sleepTime);
}
}catch(InterruptedException e){
Logger.getLogger(GameThread.class.getName()).log(Level.SEVERE,null,e);
}
}
}
Main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
engine.draw(Canvas c):
public void draw(Canvas canvas){
Paint bluepaint = new Paint(Color.BLUE);
canvas.drawRect(50,50,100,100, bluepaint);
}
EDIT:
@wondra I did test the break point, and the thread does actually get started, or so I think. The app runs and there are no errors thrown to the log console. Someone also suggested it was the emulator not running properly.
@fadden I have implemented what you suggested, still nothing... does starting the view from the xml and not from the Java have to do anything to do with it? Does the instance still exists if I don't declare it in Java?