Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


DirectX Loading Sprites and Backgrounds.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Mon Oct 15, 2007 9:06 pm    Post subject: DirectX Loading Sprites and Backgrounds. Reply with quote

Well, im currently working on my new game, but i need a bit of help displaying my Background image, as well as adding a sprite.
Both loading from .Bmp files.

I tried using a code to load the sprites.
However, it did Compile and Build, but the images did not display.
I didn't get any errors or anything such as problems, it's just that i can't see
the sprite, nor can i see the BackGround image file.

Im using C# and DirectX.

If anyone can help, please let me know of how to fix my back ground and sprite problem.

Thanks
-ZenXChaos-

P.S.Press Esc to close game.



The Extension 'zip' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
TerryDonahugh
Master Cheater
Reputation: 0

Joined: 12 Sep 2007
Posts: 412
Location: .nl

PostPosted: Tue Oct 16, 2007 4:15 am    Post subject: Reply with quote

If you want people to help you will have to post the source instead of the executable Smile
Back to top
View user's profile Send private message Send e-mail
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Tue Oct 16, 2007 5:31 am    Post subject: Reply with quote

TerryDonahugh wrote:
If you want people to help you will have to post the source instead of the executable Smile


All i need is the code to add a sprite.
I don't need any other kind of help.

Do you have the code?

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
TheIndianGuy
Advanced Cheater
Reputation: 102

Joined: 14 Jan 2007
Posts: 88

PostPosted: Tue Oct 16, 2007 4:35 pm    Post subject: Reply with quote

TerryDonahugh wrote:
If you want people to help you will have to post the source instead of the executable Smile



edit: you will probably be more successful in creating a DDR copy in Flash =)
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Tue Oct 16, 2007 7:26 pm    Post subject: Reply with quote

I don't have to post the source code to get a code.....It isn't like i have an error, i just need the code to load a Spriute to the form.

Also, it isn't just DDR, so im making it in flash.

It will be an online game, and i will add more than just DDR, in the later versions.

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Oct 16, 2007 8:32 pm    Post subject: Reply with quote

See if this helps ya:

http://www.chadvernon.com/blog/tutorials/managed-directx-2/sprites-and-2d/

And the full tutorial list:
http://www.chadvernon.com/blog/tutorials/managed-directx-2/
Back to top
View user's profile Send private message Visit poster's website
Poent
Cheater
Reputation: 0

Joined: 24 Apr 2007
Posts: 32

PostPosted: Wed Oct 17, 2007 1:44 am    Post subject: Reply with quote

Okay i'm having a problem here.. You said you were making it in C# using the DirectX API but you're using flash?

Quote:
Also, it isn't just DDR, so im making it in flash.


Quote:
I tried using a code to load the sprites.
However, it did Compile and Build, but the images did not display.


Paste that code and we should be able to help you with it. There are two possible problems. either your code is wrong (the compiler wouldn;t give you an error because it does not handle DirectX API problems), or you simply failed to link to the images correctly (most likely).

Because you asked however, I'll post some older code that I did last year for my senior project when i began learning DirectX myself.

I don't like .net and it's going to limit your control over applications if you continue to use it, especially for DirectX, but for your sake I'll post some basic DirectX sprite stuff using .NET (C#). Mind you I don't usually code in C# so don't turn this in for your homework and think it's right.

This code will load 1-7 kitty images located in the same root folder as the application and animate the kitty running across the screen. Mind you this is only the base .cpp file. I did not include the basic DirectX functions or the d3d9 files (I assume you already have those).

Code:
LPDIRECT3DSURFACE9 kitty_image[7];
SPRITE kitty;
LPDIRECT3DSURFACE9 back;

//timing variable
long start = GetTickCount();

//initializes the game
int Game_Init(HWND hwnd)
{
    char s[20];
    int n;

   //set random number seed
   srand(time(NULL));

    //load the sprite animation
    for (n=0; n<6; n++)
    {
        sprintf(s,"cat%d.bmp",n+1);
        kitty_image[n] = LoadSurface(s, D3DCOLOR_XRGB(255,0,255));
        if (kitty_image[n] == NULL)
            return 0;
    }

    back = LoadSurface("background.bmp", NULL );


    //initialize the sprite's properties
    kitty.x = 100;
    kitty.y = 150;
    kitty.width = 96;
    kitty.height = 96;
    kitty.curframe = 0;
    kitty.lastframe = 5;
    kitty.animdelay = 2;
    kitty.animcount = 0;
    kitty.movex = 8;
    kitty.movey = 0;

    //return okay
    return 1;
}

//the main game loop
void Game_Run(HWND hwnd)
{
    RECT rect;

    //make sure the Direct3D device is valid
    if (d3ddev == NULL)
        return;


        //after short delay, ready for next frame?
        //this keeps the game running at a steady frame rate
        if (GetTickCount() - start >= 30)
        {
            //reset timing
            start = GetTickCount();

            //move the sprite
            kitty.x += kitty.movex;
            kitty.y += kitty.movey;

            //"warp" the sprite at screen edges
            if (kitty.x > SCREEN_WIDTH - kitty.width)
                kitty.x = 0;
            if (kitty.x < 0)
                kitty.x = SCREEN_WIDTH - kitty.width;
           
            //has animation delay reached threshold?
            if (++kitty.animcount > kitty.animdelay)
            {
                //reset counter
                kitty.animcount = 0;

                //animate the sprite
                if (++kitty.curframe > kitty.lastframe)
                    kitty.curframe = 0;
            }
       }

        //start rendering
        if (d3ddev->BeginScene())
        {
            //erase the entire background
            //d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0));
            d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);


            //set the sprite's rect for drawing
            rect.left = kitty.x;
            rect.top = kitty.y;
            rect.right = kitty.x + kitty.width;
            rect.bottom = kitty.y + kitty.height;

            //draw the sprite
            d3ddev->StretchRect(kitty_image[kitty.curframe], NULL, backbuffer, &rect, D3DTEXF_NONE);

       
        //stop rendering
        d3ddev->EndScene();
    }

    //display the back buffer on the screen
    d3ddev->Present(NULL, NULL, NULL, NULL);

    //check for escape key (to exit program)
    if (KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY, 0, 0);

}

//frees memory and cleans up before the game ends
void Game_End(HWND hwnd)
{
    int n;

    //free the surface
    for (n=0; n<6; n++)
        kitty_image[n]->Release();

    back->Release();
}


here is the DirectX stuff that I relocated to keep my main game code cleaner. This was actually built to handle more than just sprites, but i'll post the whole thing for convenience sake.

Code:
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;

int Init_Direct3D(HWND hwnd, int width, int height, int fullscreen)
{
    //initialize Direct3D
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (d3d == NULL)
    {
        MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK);
        return 0;
    }

    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = (!fullscreen);
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;
    d3dpp.hDeviceWindow = hwnd;

    //create Direct3D device
    d3d->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        hwnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &d3dpp,
        &d3ddev);

    if (d3ddev == NULL)
    {
        MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK);
        return 0;
    }

    //clear the backbuffer to black
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

    //create pointer to the back buffer
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);  /*remember, &backbuffer is actually &LPDIRECT3DSURFACE9. This was for simplification and ease of understanding for myself.. way back when)*/

    return 1;
}

LPDIRECT3DSURFACE9 LoadSurface(char *filename, D3DCOLOR transcolor)
{
    LPDIRECT3DSURFACE9 image = NULL;
    D3DXIMAGE_INFO info;
    HRESULT result;
   
    //get width and height from bitmap file
    result = D3DXGetImageInfoFromFile(filename, &info);
    if (result != D3D_OK)
        return NULL;

    //create surface
    result = d3ddev->CreateOffscreenPlainSurface(
        info.Width,         //width of the surface
        info.Height,        //height of the surface
        D3DFMT_X8R8G8B8,    //surface format
        D3DPOOL_DEFAULT,    //memory pool to use
        &image,             //pointer to the surface
        NULL);              //reserved (always NULL)

    if (result != D3D_OK)
        return NULL;

    //load surface from file into newly created surface
    result = D3DXLoadSurfaceFromFile(
        image,              //destination surface
        NULL,               //destination palette
        NULL,               //destination rectangle
        filename,           //source filename
        NULL,               //source rectangle
        D3DX_DEFAULT,       //controls how image is filtered
        transcolor,         //for transparency (0 for none)
        NULL);              //source image info (usually NULL)

    //make sure file was loaded okay
    if (result != D3D_OK)
        return NULL;

    return image;
}
[/quote]
_________________


There Are No Stupid Questions, But There Are A Lot Of Inquisitive Idiots.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Wed Oct 17, 2007 4:43 am    Post subject: Reply with quote

http://www.directxtutorial.com/Tutorial9/D-GameDisplay/dx9D.aspx

explore this site

_________________
Back to top
View user's profile Send private message
Uzeil
Moderator
Reputation: 6

Joined: 21 Oct 2006
Posts: 2411

PostPosted: Wed Oct 17, 2007 4:40 pm    Post subject: Reply with quote

I haven't read anything at all on this page other than the title, and I'll just reference you to DB's source for his DirectX game. (I don't have the link, and the files are on another computer. You'll have to ask around or ask him.)
_________________


Mini Engine v3.0
Mipla v1.0

Reposted old threads out of the MS section.
Back to top
View user's profile Send private message
ZenX
Grandmaster Cheater Supreme
Reputation: 1

Joined: 26 May 2007
Posts: 1021
Location: ">>Pointer<<" : Address 00400560 Offset :1FE

PostPosted: Sat Oct 20, 2007 9:53 am    Post subject: Reply with quote

Lol, im not using flash......
what gave you the impression i was using flash?

Edit:
Oops.i meant Im adding more than just DDR, so im NOT using flash.

_________________
CEF Moderator since 2007 ^_^
ZenX-Engine
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites