Recent

Author Topic: Static and dynamic TBGRABitmap objects.  (Read 4975 times)

Khelle

  • Newbie
  • Posts: 6
Static and dynamic TBGRABitmap objects.
« on: December 29, 2011, 09:46:24 pm »
Hi everyone,
so Im still creating a game, and I have encountered next problem I cannot solve.
Im creating game field with something like that:

Code: [Select]
bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

{here Im creating game elements using another TBGRA variable - img and function bimg.PutImage();}

bimg.Draw(Canvas,0,0,True);
bimg.Free;

Game is refreshed every 40 ms, so I have to use True in the Draw mode, simply to clear the field and redraw it properly - each object with new coords etc.
But I would like to add graphical wallpaper beneath it, that doesnt need to be refreshed - I mean, a static wallpaper in .jpg format, res, maybe 1280x800px and there is my problem.

If I replace:
Code: [Select]
bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

with

Code: [Select]
bimg := TBGRABitmap.Create('./graphics/wallpaper.jpg');

Game starts to lag awfully - Im not surprised, if such a big file is loaded so many times.
I think it should work properly if I do not draw bimg on form Canvas but on wallpaper Canvas. I mean, to put bimg beyond wallpaper and refresh only bimg, without rest.
It should be fine, but... how to do it?
I tried something like

Code: [Select]
bimg.Draw(wallpaper.Canvas,0,0,True);

But It doesnt work.
Can someone help me with this? How should I code it?

lainz

  • Guest
Re: Static and dynamic TBGRABitmap objects.
« Reply #1 on: December 29, 2011, 11:49:18 pm »
Hi everyone,
so Im still creating a game, and I have encountered next problem I cannot solve.
Im creating game field with something like that:

Code: [Select]
bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

{here Im creating game elements using another TBGRA variable - img and function bimg.PutImage();}

bimg.Draw(Canvas,0,0,True);
bimg.Free;

Game is refreshed every 40 ms, so I have to use True in the Draw mode, simply to clear the field and redraw it properly - each object with new coords etc.
But I would like to add graphical wallpaper beneath it, that doesnt need to be refreshed - I mean, a static wallpaper in .jpg format, res, maybe 1280x800px and there is my problem.

If I replace:
Code: [Select]
bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

with

Code: [Select]
bimg := TBGRABitmap.Create('./graphics/wallpaper.jpg');

Game starts to lag awfully - Im not surprised, if such a big file is loaded so many times.
I think it should work properly if I do not draw bimg on form Canvas but on wallpaper Canvas. I mean, to put bimg beyond wallpaper and refresh only bimg, without rest.
It should be fine, but... how to do it?
I tried something like

Code: [Select]
bimg.Draw(wallpaper.Canvas,0,0,True);

But It doesnt work.
Can someone help me with this? How should I code it?

You need to create the image only one time, for example 'OnCreate' event.

OnDestroy free the image.

Khelle

  • Newbie
  • Posts: 6
Re: Static and dynamic TBGRABitmap objects.
« Reply #2 on: December 30, 2011, 04:03:00 am »
I know that. It is just as I wrote before.
However, I dont know how to handle drawing o wallpaper instead of pure canvas.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Static and dynamic TBGRABitmap objects.
« Reply #3 on: December 30, 2011, 03:08:07 pm »
You must defined a form variable (in the class definition of your form). Add there something like "wallpaper: TBGRABitmap".

Then in OnCreate, assign wallpaper with Create(filename)

Then when drawing :
Code: [Select]
bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRABlack); //avoid transparency as you draw in opaque mode
bimg.Fill(wallpaper); //add this line

{here Im creating game elements using another TBGRA variable - img and function bimg.PutImage();}

bimg.Draw(Canvas,0,0,True);
bimg.Free;
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018