Thread: Drawing Sprites

Results 1 to 7 of 7
  1. #1
    roabx1's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    USA
    Posts
    184
    Reputation
    10
    Thanks
    57

    Drawing Sprites

    I am here to show you how to draw sprites. Please, thank me if I helped you.

    First, we shall define our byte array. In drawing sprites, a byte array is required to draw from. To convert an image into a byte array, I take a hex editor and open the image in it. I then copy all of the bytes, and run them in my custom made program. What would be easier for you is to just google a 'file to byte array converter' and use one. NOTE: This will be INSANELY long bytes since its defining an image.

    After we are through with the byte array conversion and blah, we define it in our code. In this example, we are defining it in a header file called "Sprites.h":

    Code:
    #ifndef _CSPRITES_H
    #define _CSPRITES_H
    
    BYTE Sprite_Byted[] = { 0x89 , 0x50 , 0x4e , 0x47 , 0x0d , 0x0a , 0x1a , 0x0a , 0x00 , 0x00 , 0x00 , 0x0d , 0x49 }; //replace with your byte ;) mine was longer, but it would've taken up a page of code, haha
    
    #endif
    Now then, that is our header file.

    After we are done with our header file, its time to write some real code. In this part, it creates the sprite so that it is ready to be drawn. I put this into my file that defined my D3DMenu structs.

    Code:
    D3DXVECTOR3 pSprite;
    LPDIRECT3DTEXTURE9 texSprite;
    LPD3DXSPRITE sSprite;	
    
    #include "Sprites.h"
    
    void CreateSprite(LPDIRECT3DDEVICE9 pDevice)
    {
    	pSprite.x=0.0f; pSprite.y=0.0f; pSprite.z=0.0f; // SPRITES POSITION
    	
    	if(texSprite == NULL)D3DXCreateTextureFromFileInMemoryEx(pDevice
    			,&Sprite_Byted,sizeof(Sprite_Byted),135,500,D3DX_DEFAULT,0,D3DFMT_UNKNOWN // (135,500) are the X and Y size of the sprite. :)
    			,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&texSprite);
    	if(sSprite==NULL) D3DXCreateSprite(pDevice, &sSprite);
    }
    The next bit of code goes into where it shows/hides the menu. Put it after the code where it checks if the menu is supposed to be drawn or not (visible/not visible). This is the most important part.

    Code:
    CreateSprite(pDevice);
    sSprite->Begin(D3DXSPRITE_ALPHABLEND);
    sSprite->Draw(texSprite, NULL, NULL, &pSprite, 0xFFFFFFFF);
    sSprite->End();
    sSprite->OnLostDevice();
    sSprite->OnResetDevice();
    Voila, you now have spiced up your menu with a background. Thanks button is below

    If you have problems, just PM me or reply in this thread. This HAS been tested several times in some of my D3Ds and each time has worked.
    "Time is the wisest counselor of all." - Pericles

  2. The Following 2 Users Say Thank You to roabx1 For This Useful Post:

    nielshetschaap (09-07-2011),Terell. (08-28-2011)

  3. #2
    Mike Shinoda's Avatar
    Join Date
    May 2008
    Gender
    male
    Location
    127.0.0.1
    Posts
    1,177
    Reputation
    67
    Thanks
    165
    My Mood
    Amazed
    so the sprites replace your border with that image you choose?
    It always starts with one thing...

  4. #3
    barcoder's Avatar
    Join Date
    Jul 2011
    Gender
    male
    Location
    Visual Studio C++
    Posts
    265
    Reputation
    14
    Thanks
    88
    My Mood
    Happy
    not the border, the whole background

  5. #4
    roabx1's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    USA
    Posts
    184
    Reputation
    10
    Thanks
    57
    Quote Originally Posted by makis5 View Post
    so the sprites replace your border with that image you choose?
    Sprites can replace anything you choose, you can have multiple ones placed anywhere on the screen.
    "Time is the wisest counselor of all." - Pericles

  6. #5
    Mike Shinoda's Avatar
    Join Date
    May 2008
    Gender
    male
    Location
    127.0.0.1
    Posts
    1,177
    Reputation
    67
    Thanks
    165
    My Mood
    Amazed
    Quote Originally Posted by roabx1 View Post
    Sprites can replace anything you choose, you can have multiple ones placed anywhere on the screen.
    can you show me via tv how to do ? i want to learn not just c/p
    It always starts with one thing...

  7. #6
    Terell.'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    JAMAICAA
    Posts
    6,923
    Reputation
    273
    Thanks
    1,163
    My Mood
    Angry
    Added to hack source resources. Good job roabx.

    Warrock Minion 8-13-2011 - N/A
    A.V.A Minion since 11-1-11 - 11-12-11

  8. #7
    _Apostolos_'s Avatar
    Join Date
    Aug 2011
    Gender
    male
    Location
    Athnes, Greece
    Posts
    129
    Reputation
    62
    Thanks
    70
    My Mood
    Amused
    That's very good.... i will try it
    Thanks

Similar Threads

  1. DirectX drawing 2D sprites STUPID EXCEPTION
    By PsychicSounds in forum C++/C Programming
    Replies: 9
    Last Post: 05-08-2011, 09:16 AM
  2. [RELEASE] How To Draw Sprites
    By ac1d_buRn in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 37
    Last Post: 10-12-2010, 05:50 AM
  3. Direct3D sprites
    By arunforce in forum C++/C Programming
    Replies: 23
    Last Post: 09-16-2007, 01:18 AM
  4. Sprite Sig
    By jadedfrog in forum Art & Graphic Design
    Replies: 12
    Last Post: 08-22-2006, 12:28 AM
  5. rtp sprites
    By darkone1149 in forum Art & Graphic Design
    Replies: 0
    Last Post: 04-12-2006, 09:06 PM