Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: help with Bitblt plz someone tht also knows vb lol.

  1. #1

    help with Bitblt plz someone tht also knows vb lol.

    Ok in vb i drew sprites ina game like this.

    Clear Form
    BitBlt Mask
    BitBlt Picture
    Refresh Form

    1.Delphi has no .Cls or Clear methods nor does PaintBox.
    2.None of delphi's components have a autoredraw property.

    Does anybody know how i can do this very same thign in delphi 7?

    i can BitBlt and Refresh at da end but it flickers like crazy.

    EDIT: sorry bout the double post dont know what happened there.
    Weeeeeeee!!!!!!!

  2. #2

    help with Bitblt plz someone tht also knows vb lol.

    You might want to investigate the "DoubleBuffered" property - just put the following line of code into your form's OnCreate event:

    [pascal]DoubleBuffered := True;[/pascal]

    If you do that then you get the best effect by doing your drawing in the relevant OnPaint procedure. You could use a timer set to refresh the relevant object (the form, a paintbox, or whatever you're drawing onto). Check out the Repaint, Refresh and Invalidate methods...

    (Side note: TTimer ain't too accurate, but it'll do for a start.)

    Now, getting sprites is pretty straightforward - you don't need to mask out the objects manually. Instead, you can just load up the object into a TBitmap and set the Transparent property to true (and maybe the TransparentColor beforehand, if you want). This means that the sprite will be drawn transparently if you use the Draw method for the relevant canvas (e.g. Canvas.Draw for your form or Paintbox1.Canvas.Draw if you're using a paintbox - you get the idea).

    I'll send you an email with source for a very basic example of this. As a side don't - don't expect brilliant speed using bog-standard Windows drawing, but I guess you wouldn't expect that anyway. Once you want to get better results, look to something else like DirectX, OpenGL or Direct3D.

    EDIT: or at least, I'll send you a basic example once I get your email address. Doh!
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    help with Bitblt plz someone tht also knows vb lol.

    im wondering if using the OnPaint event is a little overkill as i only wish to redraw sprite/sprites when necessary.
    Weeeeeeee!!!!!!!

  4. #4

    help with Bitblt plz someone tht also knows vb lol.

    Code:
    Procedure PlayDraw;
    Begin
        FrmMain.Repaint;
    //Now blit them into screen combined for transparency effect.
        BitBlt&#40;FrmMain.Canvas.Handle, ShipX, ShipY, ShipMask.Width, ShipMask.Height, ShipMask.Canvas.Handle, 0, 0, SRCAND&#41;;
        BitBlt&#40;FrmMain.Canvas.Handle, ShipX, ShipY, Ship.Width, Ship.Height, Ship.Canvas.Handle, 0, 0, SRCPAINT&#41;;
    End;
    This is what i have atm ive tryed many various combinations of using InvaliDate, ReFresh and the Repaint method. This is the only one that seems to flicker less but still flickery. I also set the forms doublebuffered to true in the OnCreate event.

    This procedure is being called in the OnKeyDown event of the form just checking for left keypress/hold for testing and it flickers pretty bad but not as worse as before lol.
    Weeeeeeee!!!!!!!

  5. #5

    help with Bitblt plz someone tht also knows vb lol.

    Don't use Repaint, Invalidate, etc. They will always cause some serious flickering and they're not intended for just erasing the background of a canvas either.

    To properly erase the background, try this:

    [pascal]
    with Canvas do
    begin
    Pen.Color := Form1.Color;
    Brush.Color := Form1.Color;
    Rectangle(ClipRect);
    end;
    [/pascal]

    To completely avoid flickering, draw everything on a buffer first and then draw it onto the canvas. Example:

    [pascal]
    var
    Buffer: TBitmap;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Buffer := TBitmap.Create;
    Buffer.Width := Form1.ClientWidth;
    Buffer.Height := Form1.ClientHeight;
    end;

    procedure TForm1.FormClose(Sender: TObject);
    begin
    Buffer.Free;
    end;

    procedure TForm1.DrawMyStuff;
    begin
    with Buffer.Canvas do
    begin
    Pen.Color := clRed;
    Brush.Color := clRed;
    Rectangle(ClipRect);
    Draw(PlayerX, PlayerY, Image1.Picture.Bitmap);
    end;

    // Flip the buffer onto the screen
    Form1.Canvas.Draw(0, 0, Buffer);
    end;

    procedure TForm1.FormKeyDown(....);
    begin
    if Key = VK_LEFT then
    PlayerX := PlayerX - 1
    ...
    DrawMyStuff;
    end;
    [/pascal]

    If you choose to draw directly onto the form canvas instead of the canvas of paint box, you should also handle the OnPaint event. Otherwise the stuff you draw onto the canvas will get lost when someone drags another window over yours.
    Ask me about the xcess game development kit

  6. #6

    help with Bitblt plz someone tht also knows vb lol.

    Ok so maybe i should use a paintbox that's easy enuf except i get error in source code trying to access its properties in my procedure.
    Weeeeeeee!!!!!!!

  7. #7

    help with Bitblt plz someone tht also knows vb lol.

    post the line that gives you the error message...
    Ask me about the xcess game development kit

  8. #8

    help with Bitblt plz someone tht also knows vb lol.

    There's no line its an error in the source code it says like if i type....

    PaintBox.

    the error comes up theres nothing wrong with the source except my proc isnt declared in private or public and doesnt use TForm.Proc.
    Weeeeeeee!!!!!!!

  9. #9

    help with Bitblt plz someone tht also knows vb lol.

    if your procedure is not part of your form, you'll have to access the paintbox like this:

    Form1.PaintBox.Width := 200;

    Hope I understood what you mean
    Ask me about the xcess game development kit

  10. #10

    help with Bitblt plz someone tht also knows vb lol.

    i think so although i could declare it i just stick the proc name in private and then slap TForm. infront of proc name in the actual proc :lol:
    Weeeeeeee!!!!!!!

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •