using a bitmap as a player in directx

Started by
7 comments, last by Palidine 19 years, 2 months ago
im trying to make this little pacman game using directx in C++, and have all the little bitmaps and things for models. How would i set the bitmap as an object so that it could be moved around with the keyboard? Also, i have another bitmap set as the background, how would i make it so the player models would show over the background? for example if( GetAsyncKeyState( VK_LEFT ) ) { working code.. } thanks
Advertisement
Eh?

How exactly are you displaying the things? That would help greatly in providing a better answer.

The general generic answer is, "How do you know where to place it in the first place?". Whatever way that is, modify that when the keypress is true, and don't when it's false...
Eh, silly me, hit reply, look away and forget the topic.

So. Using directX, you change the coordinates of the bitmap, either via a transformation [if you're using 3D] or by directly editing the vertex data [if you're using the 2D projection] or by changing the center/location vector [if you're using ID3DXSprite].
I get the concept of how i would move it, but i dont know the correct sytax to go about doing it, How would i edit the coordinates of the bitmap to make it move using a certain argument, function?
Quote:Original post by CodeWeasil
I get the concept of how i would move it, but i dont know the correct sytax to go about doing it, How would i edit the coordinates of the bitmap to make it move using a certain argument, function?


How do you know where to place the bitmap in the first place?
How are the coordinates stored?

It could be any number of ways, even within DirectX...
the coords im using are stored within this function
BitBlt( hDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, hBitmapDC, 0, 0, SRCCOPY )


the first 0's are the coordinates. the code is in the WM_PAINT: case, btw.

something else about the bitmaps, I have it so it is just the player model and there is no background, but when i put it in the program it shows with a white background. Anyone know how to fix that?
Quote:Original post by CodeWeasil
the first 0's are the coordinates. the code is in the WM_PAINT: case, btw.


so change the coordinates and it appears in a different place. change the coordinates each frame, and you have movement.

-me
Quote:Original post by Palidine
Quote:Original post by CodeWeasil
the first 0's are the coordinates. the code is in the WM_PAINT: case, btw.


so change the coordinates and it appears in a different place. change the coordinates each frame, and you have movement.

-me


I know how i would do it if i was changing the numbers of the coords each time. but, I know there has to be some command to move it up 1 pixel each time. In stead of me having to change the numbers manually.
Quote:Original post by CodeWeasil
I know how i would do it if i was changing the numbers of the coords each time. but, I know there has to be some command to move it up 1 pixel each time. In stead of me having to change the numbers manually.


You would store variables for the coordinates and change those each frame, then the draw call would look somthing like:

BitBlt( hDC, playerPosX, playerPosY, Bitmap.bmWidth, Bitmap.bmHeight, hBitmapDC, 0, 0, SRCCOPY )


to back up a little further here is a vague and very very general example of a game update loop:

while (1){    if ( ShouldExitGame() )        break;    Update();    Draw();}


the update function would do all the things that would determine the new position of the player. In your case, I think the Draw function would exist wherever you are handling the WM_PAINT message and not in the loop as I have it above.

-me

This topic is closed to new replies.

Advertisement