Sign in to follow this  
CodeWeasil

using a bitmap as a player in directx

Recommended Posts

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 [CODE] if( GetAsyncKeyState( VK_LEFT ) ) { working code.. } [/CODE] thanks

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this