Hi,
Ive started on doing some animations in win32 but i cant seem to know how to set the starting position without messing up the movement. Also all my animations are flickering.
this is my code so far exluding the intializing, windows creations and such.

typedef struct _REDINFO
{
    int width;
	int height;
	int x;
	int y;

	int dx;
	int dy;
} REDINFO;

REDINFO g_fireinfo;
REDINFO g_earthinfo;
REDINFO g_waterinfo;

HBITMAP g_hbmGround = NULL;
HBITMAP g_hbmCustom = NULL;
HBITMAP g_hbmFire = NULL;
HBITMAP g_hbmEarth = NULL;
HBITMAP g_hbmWater = NULL;



void DrawFire(HDC hdc, RECT* prc)
{
    BITMAP bm;

	HDC hdcBuffer = CreateCompatibleDC(hdc);
	HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
	HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hdcBuffer, hbmBuffer);

	HDC hdcMem = CreateCompatibleDC(hdc);


          if (background == 0)
            {
                SelectObject(hdcMem, g_hbmGround);
                BitBlt(hdc, 0, 0, 800, 600, hdcMem, 0, 0, SRCCOPY);
            }


            if (background == 1)
            {
                SelectObject(hdcMem, g_hbmCustom);
                BitBlt(hdc, 0, 0, 800, 600, hdcMem, 0, 0, SRCCOPY);
            }

	SelectObject(hdcMem, g_hbmFire);
	BitBlt(hdcBuffer,g_fireinfo.x , g_fireinfo.y , g_fireinfo.width , g_fireinfo.height, hdcMem, 0, 0, SRCCOPY);

    SelectObject(hdcMem, g_hbmEarth);
    BitBlt(hdcBuffer, g_earthinfo.x, g_earthinfo.y, g_earthinfo.width , g_earthinfo.height, hdcMem, 0, 0, SRCCOPY);

    SelectObject(hdcMem, g_hbmWater);
    BitBlt(hdcBuffer, g_waterinfo.x, g_waterinfo.y, g_waterinfo.width , g_waterinfo.height, hdcMem, 0, 0, SRCCOPY);

    BitBlt(hdc, 0, 0, prc->right, prc->bottom, hdcBuffer, 0, 0, SRCPAINT);

	SelectObject(hdcMem, NULL);
	DeleteDC(hdcMem);

	SelectObject(hdcBuffer, hbmOldBuffer);
	DeleteObject(hbmBuffer);

}

void UpdateFire(RECT* prc)
{

    g_fireinfo.x += g_fireinfo.dx;
	g_fireinfo.y += g_fireinfo.dy;

	if(g_fireinfo.x < 0)
	{
		g_fireinfo.x = 0;
		g_fireinfo.dx = FIRE_MOVE_DELTA;
	}
	else if(g_fireinfo.x + g_fireinfo.width > prc->right)
	{
		g_fireinfo.x = prc->right - g_fireinfo.width;
		g_fireinfo.dx = -FIRE_MOVE_DELTA;
	}

	if(g_fireinfo.y < 0)
	{
		g_fireinfo.y = 0;
		g_fireinfo.dy = FIRE_MOVE_DELTA;
	}
	else if(g_fireinfo.y + g_fireinfo.height > prc->bottom)
	{
		g_fireinfo.y = prc->bottom - g_fireinfo.height;
		g_fireinfo.dy = -FIRE_MOVE_DELTA;
	}
}

FIRE_MOVE_DELTA is there just not in this small piece of code

Recommended Answers

All 2 Replies

C++ doesn't support animation very well -- better off using something like DirectX or OpenGL

I shouldnt really refer this to animation: just a small simulation to run then. But that isnt really the problem , i know there are better languages and libs for animation. But that isnt my focus.

My question remains unanswered : How to set the starting position without screwing the movement up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.