Link to home
Start Free TrialLog in
Avatar of Yuri Cacher
Yuri Cacher

asked on

BufferStrategy questions

I'm trying to understand this code, tell me if my considerations are correct

//bs is a BufferStrategy object

public void gameLoop()
{ 
    do
    {
        do
        {
             Graphics g=null;
             try
                 {
                     g=bs.getDrawGraphics();
                     g.clearRect(0,0,getWidth(),getHeight());
                     render(g);
                 }
             finally
             {
                 if(g!=null)
                 {
                     g.dispose();
                 }
             }
        }
        while(bs.contentsRestored());
        bs.show();
     }
    while(bs.contentsLost());
}

Open in new window


    The getDrawGraphics give me a buffer zone where write , the render method create the frame in that space.
    If the frame is correctly create the dispose method releases system resources by the buffer zone.
    The contentsRestored() is called due a lost and it implies that the frame have to be redrawn.
    The contentsLost is not clear to me...
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpearson
dpearson

Only contribution and seemed to be on point.