Link to home
Start Free TrialLog in
Avatar of kyriakos70
kyriakos70

asked on

directx animate bitmap

Hello,
I have a directx 9 application, I have some bitmaps in png and want to animate them like falling down (like tetris free fall down), any help I am a niewbie?

Thank you
Kyriakos
(I will provide code if necessary)
Avatar of Member_2_5069294
Member_2_5069294

The question isn't getting many answers because its not badly defined.  Its almost like your asking us to explain how to write a program.  If an Expert tells you what code to write then you haven't written the program, the Expert did.  If you explain what is working so far, and show some code, you're much more likely to get some answers.
Avatar of kyriakos70

ASKER

OK,
Problem 1) I have the first code and create a window 1024x768, the bitmap is also 1024x768 but it is not showing all of the bitmap, the bottom is cut doesn't fit to the window, is there any code to make it fit to the window the dimensions are the same even if I insert a rect with other dimensions and enter it like this d3dspt->Draw(sprite, &rct, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));
it is not showing correct?
problem 2) I need to make a n animation that change the position x ok I done it through satsumo's answer, I have to do is to stop the falling bitmap to a given location or if under it there is another bitmap. I have some code and provide it for this question too.
Sorry for the 2 questions if need I will create a new one to answer it and give the points.

Kyriakos
#define SCREEN_WIDTH  1024
#define SCREEN_HEIGHT 768
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
LPDIRECT3D9 d3d;    
LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
LPD3DXSPRITE d3dspt;    // the pointer to our Direct3D Sprite interface
LPD3DXSPRITE d3dspt1;
LPDIRECT3DDEVICE9 d3ddev1;

// sprite declarations
LPDIRECT3DTEXTURE9 sprite;    // O pointer GIA TO sprite
LPDIRECT3DTEXTURE9 sprite1;
// function prototypes
void initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = "WindowClass1";
    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          "WindowClass1",
                          "Our Direct3D Program",
                          WS_EX_TOPMOST | WS_POPUP,
                          0, 0,
                          SCREEN_WIDTH, SCREEN_HEIGHT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
    ShowWindow(hWnd, nCmdShow);
    // set up and initialize Direct3D
    initD3D(hWnd);
    // enter the main loop:
    MSG msg;
    while(TRUE)
    {
        DWORD starting_point = GetTickCount();
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                break;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        render_frame();
       // check the 'escape' key
        if(KEY_DOWN(VK_ESCAPE))
            PostMessage(hWnd, WM_DESTROY, 0, 0);
        while ((GetTickCount() - starting_point) < 25);
    }
    // clean up DirectX and COM
    cleanD3D();
    return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }
    return DefWindowProc (hWnd, message, wParam, lParam);
}
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS d3dpp;

    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth = SCREEN_WIDTH;    d3dpp.BackBufferHeight = SCREEN_HEIGHT;
//edo na valo kai kodika gia 1024x768
 // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
    D3DXCreateSprite(d3ddev, &d3dspt);
 D3DXCreateTextureFromFile(d3ddev, "back_temp2.png", &sprite);
    return;
}
void render_frame(void)
{
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);    // center at the upper-left corner
D3DXVECTOR3 position(0.0f, 0.0f, 0.0f);
3ddev->BeginScene();    // begins the 3D scene
 d3dspt->Begin(NULL);    // begin sprite drawing	
d3dspt->Draw(sprite, NULL, &center, &position, D3DCOLOR_XRGB(255, 255, 255));
 d3dspt->End();    // end sprite drawing

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);

    return;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_5069294
Member_2_5069294

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello satsumo,
Here is what movement I am trying to achieve, in the ling you will find a slot machine, I want to do the spinning of the reels, I think I must create a rectangle and import ramndom bitmaps of the figures, eg for the first figure must appear 3 times the second must 2 times, but from a list of figures like
code below and with a random() function to show the bitmaps?
https://flashcasino.ladbrokes.com/instant-play-en/1clickStart.asp?sEXT1=demo&sEXT2=demo&gameID=thunderstruck2.

Thank you again satrumo
IDirect3DTexture9 *sprite[2];
D3DXCreateTextureFromFile(d3ddev, "Panel1.png", &sprite[0]);
D3DXCreateTextureFromFile(d3ddev, "Panel1.png", &sprite[1]);

Open in new window

Kyriakos, I do not feel I can continue to answer until you show that you have some understanding of programming.  None of the questions you have asked or code you have posted demonstrate any kind of development on your part.  The code you show appears to be from other sources.  

If you can program, then I would be willing to help, if you make an attempt to program the game.  The answers you already have contain enough information.  Another expert may be willing to write the program as an answer to this question.  Writing games is my job and I don't work for EE.
kyriakos70, thank you for accepting the solution.  I hope your game development is a success.