Forum > BGRABitmap and LazPaint

Static and dynamic TBGRABitmap objects.

(1/1)

Khelle:
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: ---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;

--- End code ---

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: ---bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

--- End code ---

with


--- Code: ---bimg := TBGRABitmap.Create('./graphics/wallpaper.jpg');

--- End code ---

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: ---bimg.Draw(wallpaper.Canvas,0,0,True);

--- End code ---

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

lainz:

--- Quote from: Khelle 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: ---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;

--- End code ---

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: ---bimg := TBGRABitmap.Create(clientWidth, clientHeight, BGRAPixelTransparent);

--- End code ---

with


--- Code: ---bimg := TBGRABitmap.Create('./graphics/wallpaper.jpg');

--- End code ---

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: ---bimg.Draw(wallpaper.Canvas,0,0,True);

--- End code ---

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

--- End quote ---

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

OnDestroy free the image.

Khelle:
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:
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: ---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;
--- End code ---

Navigation

[0] Message Index

Go to full version