Wednesday, 22 August 2007

My game library works !

I quickly put together a test and shown below is all that is required to display three sprites on the screen (As shown above).

All the code does is create an SDL rendering surface with dimensions of 800x600 with 24 bits per pixel. All the graphical content in the "Images" directory is loaded. I then create three sprite and load them into a batch handler. I then sort the batch so that the sprite will be rendered using their z-order. I then render the sprites by passing the batch to the graphics device and finally flip the buffer to show the results. The graphics device will also accept single sprites as well as a batch list and there are several other options now shown in this example. And finally, before anyone asks, I haven't shown any code that calls "free" on the objects I have created. Any comments ?

The Code

procedure TForm1.btnSpriteTestClick (Sender : TObject) ;
GraphicDev : TGraphicsDevice ;
Content : TVisualContent ;
spr1 : TTestSprite ;

spr2 : TTestSprite ;
spr3 : TTestSprite ;
Batch : TSpriteBatch ;


GraphicDev := TGraphicsDevice.Create (800, 600, bs24) ;

Content := TVisualContent.Create ('Images') ;
Content.LoadImageContent ;

spr1 := TTestSprite.Create (Content.GetImage ('Pic1'), 90, 90, 2) ;

spr2 := TTestSprite.Create (Content.GetImage ('Pic2'), 100, 100, 5) ;
spr3 := TTestSprite.Create (Content.GetImage ('Pic3'), 110, 110, 3) ;

Batch := TSpriteBatch.Create ;

Batch.Add (spr1) ;
Batch.Add (spr2) ;
Batch.Add (spr3) ;

Batch.Sort ;

GraphicDev.DrawSpriteBatch (Batch.SpriteList) ;

GraphicDev.Flip ;

end ;

No comments: