Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Smooth graphics in windows

AmanteAmante Posts: 52Member
I'm trying to develop a game in windows, of small ships moving inside the screen, i don't do any big math operations, and the sprites are small.
I use the MFC C++ of Microsoft, i don't use ActiveX, i want it simple.
I use the ::OnPaint() method to draws the screen with all compounents on it.
But still the sprites move really bad and blinking.
Isn't there a way to delete them and then draw them again, not using the ::OnPaint procedure?
Do you know a way to make them move smoothly?


Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : I'm trying to develop a game in windows, of small ships moving inside the screen, i don't do any big math operations, and the sprites are small.
    : I use the MFC C++ of Microsoft, i don't use ActiveX, i want it simple.
    : I use the ::OnPaint() method to draws the screen with all compounents on it.
    : But still the sprites move really bad and blinking.
    : Isn't there a way to delete them and then draw them again, not using the ::OnPaint procedure?
    : Do you know a way to make them move smoothly?
    :
    :

    Usually when you move some object on a client area you should refresh it with 'InvalidateRect()' function, where you pass the RECT which will be common for both the previous position of an object and its current position. You also should specify that you want to erase background. After 'InvalidateRect()' call 'UpdateWindow()' which in turn calls your own 'OnPaint()'.
    When you process 'OnPaint()' you have to use 'RectVisible()' in order to eliminate unnecessary drawings...

    To make it even smoother you can draw inside a bitmap and then 'BitBlt()' it at once.

  • AmanteAmante Posts: 52Member
    Thank you very much.
    All my drawinf is done inside the OnPaint();
    So you advise to draw outside the OnPaint();
    And then refresh?


    : : I'm trying to develop a game in windows, of small ships moving inside the screen, i don't do any big math operations, and the sprites are small.
    : : I use the MFC C++ of Microsoft, i don't use ActiveX, i want it simple.
    : : I use the ::OnPaint() method to draws the screen with all compounents on it.
    : : But still the sprites move really bad and blinking.
    : : Isn't there a way to delete them and then draw them again, not using the ::OnPaint procedure?
    : : Do you know a way to make them move smoothly?
    : :
    : :
    :
    : Usually when you move some object on a client area you should refresh it with 'InvalidateRect()' function, where you pass the RECT which will be common for both the previous position of an object and its current position. You also should specify that you want to erase background. After 'InvalidateRect()' call 'UpdateWindow()' which in turn calls your own 'OnPaint()'.
    : When you process 'OnPaint()' you have to use 'RectVisible()' in order to eliminate unnecessary drawings...
    :
    : To make it even smoother you can draw inside a bitmap and then 'BitBlt()' it at once.
    :


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    No, no, no...
    All you drawing is inside OnPaint(); just use 'RectVisible()' - it will give you better performance:

    void OnPaint()
    {
    RECT rectShip;

    for (int i=0; i<nShips; i++) {
    // Calculate 'rectShip' somehow
    if (RectVisible (hDC, &rectShip)) {
    // Draw ship here, because it is in the area that
    // has been refreshed.
    }
    }
    }

    Now after you designed this 'OnPaint()' when you need to move
    a ship, then do this:

    RECT rectShipBeforeMove;
    RECT rectShipAfterMove;
    RECT rectRefresh;

    // calculate 'rectShipBeforeMove' (current ship position)
    // then shift the rect by your movement:
    rectShipAfterMove = rectShipBeforeMove;
    OffsetRect (&rectShipAfterMove, xOfsPixels, yOfsPixels);
    UnionRect (&rectRefresh, &rectShipAfterMove, &rectShipBeforeMove);

    // Refresh it:
    InvalidateRect (hWnd, &rectRefresh, TRUE);
    UpdateWindow (hWnd); // your 'OnPaint()' called inside
    ...





Sign In or Register to comment.