Quantcast
Channel: Question and Answer » game-loop
Viewing all articles
Browse latest Browse all 30

android game development: why is my screen black?

$
0
0

so, im strarting an android game from scratch, and every time I try i stumble uppon the same problem, 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 this code snippet that I got from here and most of the code is pretty much the same from that webpage and im trying to follow it correctly. However all i get from that is a black sceen.

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);
            }
        }
    }

My 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);
}

and on my engine.draw(Canvas c):

public void draw(Canvas canvas){
    Paint bluepaint = new Paint(Color.BLUE);
    canvas.drawRect(50,50,100,100, bluepaint);
}

the result is a black screen that does nothing.

EDIT: @wondra I did test the break point, the thread does actually get started, or so i think, the app gets running and there are no errors thrown to the log cat. Someone also sugested it was the emulator not running properly.

EDIT: @fadden I have implemented what you suggested, still nothing… does starting the view from the xml and not from the Java have to do anythig with it? does the instance still exists if i dont declare it on the java?


Viewing all articles
Browse latest Browse all 30

Trending Articles