Board index » delphi » Graphics problem

Graphics problem

Hi There

I am programming a small game in Delphi 5 as a way to teach myself the
program. I'm using a tile-based approach to graphics on the screen using
a Timage component to store a background and a Timagelist component to
store the tiles themselves. All my drawing in done on the mainform
canvas.

I have the following problem. If I open the program only the background
image is displayed. If I then load a savefile for the game, then the
screen is updated by placing the tiles at the correct locations. If I
then attempt to load a different savefile I start to get graphics
problems. It almost seems as if the screen is painting itself over the
TOpenDialog component before actually removing the component itself.
Consequently, for split second the screen look really as I have trees
and other tiles painted over the TOpenDialog component. I have
doublebuffering set to true to reduce flicker when repainting the
screen.

If anybody has any experience in such matters or could offer a solution
it would be much appreciated.

Thanks

Ewan

 

Re:Graphics problem


Quote
"Ewan Thiele" <tunawh...@hotmail.com> wrote in message

news:3A819CE0.70B7523D@hotmail.com...

Quote
> All my drawing in done on the mainform
> canvas.

That's fine only if you're drawing on the form's canvas in its OnPaint
handler.
Otherwise your drawing won't have any persistence.

Instead of using the OnPaint handler to control all the drawing, you can
draw
on an in-memory TBitmap, usually the same size as  a TImage, and then
display the TBitmap in a TImage.  The TImage is "smart" enough to have
persistence.

--
efg          Earl F. Glynn, Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab
Mirror:  http://homepages.borland.com/efg2lab/Default.htm

Re:Graphics problem


have your tried a controlname.refresh; command at the end of your graphics
loading routine??

I write tile editors for our company and I have had a few problems with
persistence on the image.  One good way as E.F.G. suggested is to use a
TBitmap and then when your done copy it to the TImage.  Also gotta watch how
your blitting thse tiles. If you are using API then you may need to refresh
to update the TImage. Also, if you are using the TImage as your control then
you don't need to overide the onpaint proc, it manages this for you
automatically, you would be fighting for who gets to paint

Quote
"Ewan Thiele" <tunawh...@hotmail.com> wrote in message

news:3A819CE0.70B7523D@hotmail.com...
Quote
> Hi There

> I am programming a small game in Delphi 5 as a way to teach myself the
> program. I'm using a tile-based approach to graphics on the screen using
> a Timage component to store a background and a Timagelist component to
> store the tiles themselves. All my drawing in done on the mainform
> canvas.

> I have the following problem. If I open the program only the background
> image is displayed. If I then load a savefile for the game, then the
> screen is updated by placing the tiles at the correct locations. If I
> then attempt to load a different savefile I start to get graphics
> problems. It almost seems as if the screen is painting itself over the
> TOpenDialog component before actually removing the component itself.
> Consequently, for split second the screen look really as I have trees
> and other tiles painted over the TOpenDialog component. I have
> doublebuffering set to true to reduce flicker when repainting the
> screen.

> If anybody has any experience in such matters or could offer a solution
> it would be much appreciated.

> Thanks

> Ewan

Re:Graphics problem


Hi

Thanks for the advice. It worked beautifully!

Ewan

Quote
"Earl F. Glynn" wrote:
> "Ewan Thiele" <tunawh...@hotmail.com> wrote in message
> news:3A819CE0.70B7523D@hotmail.com...

> > All my drawing in done on the mainform
> > canvas.

> That's fine only if you're drawing on the form's canvas in its OnPaint
> handler.
> Otherwise your drawing won't have any persistence.

> Instead of using the OnPaint handler to control all the drawing, you can
> draw
> on an in-memory TBitmap, usually the same size as  a TImage, and then
> display the TBitmap in a TImage.  The TImage is "smart" enough to have
> persistence.

> --
> efg          Earl F. Glynn, Overland Park, KS  USA

> efg's Computer Lab:  http://www.efg2.com/Lab
> Mirror:  http://homepages.borland.com/efg2lab/Default.htm

Re:Graphics problem


Hi

Thanks for the Reply. I've updated my code to reflect E.F.G. 's suggestion and
everything works great. Basically, I'm loading the images that are stored in a
Timagecomponent and then masking them to the "Now Brand New And Fully Operation
TImage Control" using dummy TBitmaps and the GetBitmap method. I'm not quite
sure what you mean by blitting, though. I'm not using the OnPaint Event Handler
at all at present.

Ewan

Quote
Ron wrote:
> have your tried a controlname.refresh; command at the end of your graphics
> loading routine??

> I write tile editors for our company and I have had a few problems with
> persistence on the image.  One good way as E.F.G. suggested is to use a
> TBitmap and then when your done copy it to the TImage.  Also gotta watch how
> your blitting thse tiles. If you are using API then you may need to refresh
> to update the TImage. Also, if you are using the TImage as your control then
> you don't need to overide the onpaint proc, it manages this for you
> automatically, you would be fighting for who gets to paint

> "Ewan Thiele" <tunawh...@hotmail.com> wrote in message
> news:3A819CE0.70B7523D@hotmail.com...
> > Hi There

> > I am programming a small game in Delphi 5 as a way to teach myself the
> > program. I'm using a tile-based approach to graphics on the screen using
> > a Timage component to store a background and a Timagelist component to
> > store the tiles themselves. All my drawing in done on the mainform
> > canvas.

> > I have the following problem. If I open the program only the background
> > image is displayed. If I then load a savefile for the game, then the
> > screen is updated by placing the tiles at the correct locations. If I
> > then attempt to load a different savefile I start to get graphics
> > problems. It almost seems as if the screen is painting itself over the
> > TOpenDialog component before actually removing the component itself.
> > Consequently, for split second the screen look really as I have trees
> > and other tiles painted over the TOpenDialog component. I have
> > doublebuffering set to true to reduce flicker when repainting the
> > screen.

> > If anybody has any experience in such matters or could offer a solution
> > it would be much appreciated.

> > Thanks

> > Ewan

Re:Graphics problem


BLT stands, roughly, for 'block transfer'. (Or bacon, lettuce and tomato.
=)) It refers to the process of transferring a big chunk of data from one
place to another, usually from an offscreen buffer to video memory.

- Dave

Quote
"Ewan Thiele" <tunawh...@hotmail.com> wrote in message

news:3A81C335.34491761@hotmail.com...
Quote
> Hi

> Thanks for the Reply. I've updated my code to reflect E.F.G. 's suggestion
and
> everything works great. Basically, I'm loading the images that are stored
in a
> Timagecomponent and then masking them to the "Now Brand New And Fully
Operation
> TImage Control" using dummy TBitmaps and the GetBitmap method. I'm not
quite
> sure what you mean by blitting, though. I'm not using the OnPaint Event
Handler
> at all at present.

> Ewan

> Ron wrote:

> > have your tried a controlname.refresh; command at the end of your
graphics
> > loading routine??

> > I write tile editors for our company and I have had a few problems with
> > persistence on the image.  One good way as E.F.G. suggested is to use a
> > TBitmap and then when your done copy it to the TImage.  Also gotta watch
how
> > your blitting thse tiles. If you are using API then you may need to
refresh
> > to update the TImage. Also, if you are using the TImage as your control
then
> > you don't need to overide the onpaint proc, it manages this for you
> > automatically, you would be fighting for who gets to paint

> > "Ewan Thiele" <tunawh...@hotmail.com> wrote in message
> > news:3A819CE0.70B7523D@hotmail.com...
> > > Hi There

> > > I am programming a small game in Delphi 5 as a way to teach myself the
> > > program. I'm using a tile-based approach to graphics on the screen
using
> > > a Timage component to store a background and a Timagelist component to
> > > store the tiles themselves. All my drawing in done on the mainform
> > > canvas.

> > > I have the following problem. If I open the program only the
background
> > > image is displayed. If I then load a savefile for the game, then the
> > > screen is updated by placing the tiles at the correct locations. If I
> > > then attempt to load a different savefile I start to get graphics
> > > problems. It almost seems as if the screen is painting itself over the
> > > TOpenDialog component before actually removing the component itself.
> > > Consequently, for split second the screen look really as I have trees
> > > and other tiles painted over the TOpenDialog component. I have
> > > doublebuffering set to true to reduce flicker when repainting the
> > > screen.

> > > If anybody has any experience in such matters or could offer a
solution
> > > it would be much appreciated.

> > > Thanks

> > > Ewan

Re:Graphics problem


Quote
> Instead of using the OnPaint handler to control all the drawing, you can
> draw
> on an in-memory TBitmap, usually the same size as  a TImage, and then
> display the TBitmap in a TImage.  The TImage is "smart" enough to have
> persistence.

or paint the ofscreen bitmap in OnPaint of a paintbox or the form, and
remember to set doublebuffered to false then you are douing the
"doublebuffering" yourself with the ofscreen bitmap

/David

Other Threads