[color="#16334B"]Ok, I have two problems.
1. I place a sprite that is 1024*768 and it actually doesnt cover the entire screen. There is an excess and it gets cropped out. The image is 1024*768 as well.
2. How would I exactly change from the main menu to another sprite. Do I have to clear it before I change or something?
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = 1024; // set the width of the buffer
d3dpp.BackBufferHeight = 768; // set the height of the buffer
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
//MainMenu Stuff
D3DXCreateSprite(d3ddev, &sprite);
D3DXCreateTextureFromFile(d3ddev, L"Menu.jpg", &mainmenutex);
D3DXCreateTextureFromFile(d3ddev, L"Battle.png", &battletex);
////////////
EndRender();
}Basically, if MainMenu returns 0, that means they wanted to close the game, if it returns 1, then it means they want to play. Its not exactly working though.
1) At a guess, your graphics card doesn't support non-power-of-2 sized textures so the 768 is a no-no. If my wild guess is correct, you'll need to create a 1024x1024 texture, load your image into the top part then select the appropriate source rectangle when you render. It may help if you could post us a screenshot of exactly what the result on the screen is.
2) You just pass a different texture to ID3DXSprite::Draw() I assume. ID3DXSprite is a confusingly named beast as it does not in anyway represent a specific sprite. It is an interface for drawing sprites and, as far as I know, does not retain any state after ID3DXSprite::End() is called but I'll defer to people who use it on this.
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = 1024; // set the width of the buffer
d3dpp.BackBufferHeight = 768; // set the height of the buffer
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
//MainMenu Stuff
D3DXCreateSprite(d3ddev, &sprite);
D3DXCreateTextureFromFile(d3ddev, L"Menu.jpg", &mainmenutex);
D3DXCreateTextureFromFile(d3ddev, L"Battle.png", &battletex);
The picture shows perfectly now but I had to change the dimensions of the picture from 1024 X 768 to 1024 X 588, something around there...I basically opened the picture in paint and shrinked it until it fit.
Well, that is to be expected. Every loop you draw the first image, then draw the second image only if Escape is pressed, so what you describe is the expected behaviour. I think you maybe trying to run before you can walk here.
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = 1024; // set the width of the buffer
d3dpp.BackBufferHeight = 768; // set the height of the buffer
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
//MainMenu Stuff
D3DXCreateSprite(d3ddev, &sprite);
D3DXCreateTextureFromFile(d3ddev, L"Menu.jpg", &mainmenutex);
D3DXCreateTextureFromFile(d3ddev, L"Battle.png", &battletex);
[color="#16334B"][color="#000088"][color="#000088"][color="#000088"]if[color="#666600"][color="#666600"][color="#666600"]([color="#660066"][color="#660066"][color="#660066"]MainMenu[color="#666600"][color="#666600"][color="#666600"]()[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]==[color="#000000"][color="#000000"] [color="#006666"][color="#006666"][color="#006666"]0[color="#666600"][color="#666600"][color="#666600"])[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]{[color="#000000"][color="#000000"] [color="#000088"][color="#000088"][color="#000088"]return[color="#666600"][color="#666600"][color="#666600"];[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]}[color="#000000"][color="#000000"] [color="#000088"][color="#000088"][color="#000088"]else[color="#000000"][color="#000000"] [color="#000088"][color="#000088"][color="#000088"]if[color="#666600"][color="#666600"][color="#666600"]([color="#660066"][color="#660066"][color="#660066"]MainMenu[color="#666600"][color="#666600"][color="#666600"]()[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]==[color="#000000"][color="#000000"] [color="#006666"][color="#006666"][color="#006666"]1[color="#666600"][color="#666600"][color="#666600"])[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]{[color="#000000"][color="#000000"][color="#000000"]
sprite[color="#666600"][color="#666600"][color="#666600"]->[color="#660066"][color="#660066"][color="#660066"]Draw[color="#666600"][color="#666600"][color="#666600"]([color="#000000"][color="#000000"][color="#000000"]battletex[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]&[color="#000000"][color="#000000"][color="#000000"]rct[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"][color="#000000"] NULL[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"][color="#000000"]NULL[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"][color="#000000"] D3DCOLOR_XRGB[color="#666600"][color="#666600"][color="#666600"]([color="#006666"][color="#006666"][color="#006666"]255[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"] [color="#006666"][color="#006666"][color="#006666"]255[color="#666600"][color="#666600"][color="#666600"],[color="#000000"][color="#000000"] [color="#006666"][color="#006666"][color="#006666"]255[color="#666600"][color="#666600"][color="#666600"]));[color="#000000"][color="#000000"] [color="#666600"][color="#666600"][color="#666600"]}
[color="#1C2837"][color="#16334B"]Basically, if MainMenu returns 0, that means they wanted to close the game, if it returns 1, then it means they want to play.
Again, grossly oversimplified but I'd advise you to separate the logic from rendering. Logical section of the code should deal with input and modify state accordingly (e.g. which menu option is selected, which image are we displaying on the background). State needs to be held elsewhere, either as globals in this simple example or as part of a class in a more sophisticated system.
Rendering should not be concerned with modifying state but just drawing things based on their current state.
void Render()
{
foreach(MenuItem m in menuItems)
{
if(index_of(m)==menuSelected) DrawAllSparkly(m);
else DrawNormally(m);
}
}
You would also probably be better to respond to WM_KEYDOWN messages rather than using GetAsyncKeyState() for this sort of thing as you only really want one notification when the key is first pressed, not a constant stream of notifications each frame that the key is down.
I am trying to make the sprite move when I use the UP,DOWN,LEFT,RIGHT arrow keys, but how would I exactly do that?
Im thinking it has to do with the rectangle it is in but Im not sure.
Okay, you are without question running before you can walk now. This is going to be a very long, painful process for you if you don't get some fundamental basics down before you start trying to write a Direct3D application, in my humble opinion.
Look at the documentation for ID3DXSprite::Draw(). What's the 4th parameter? The rectangle is clearly documented as being for defining the source rectangle that the image is taken from and has nothing to do with where on the screen it is drawn. The 4th parameter, quite helpfully called 'position' is the one you want to move the sprite around.
Opinion: You need to take a bit of a step back and learn some fundamental programming concepts in a simpler environment. Have you written any text-based games? Have you tried using a more user-friendly graphics library like SDL, SFML or Allegro? Have you developed the skills needed to research API calls using documentation?
Trying to get through this stuff by posting every question on an internet forum is fine, and people will always be happy to help, but it will take you literally years to achieve anything.
What that will do will of course depend upon what view and projection matrices you have set up but given your previous examples of drawing the static images, I'm assuming that you are (0,0,0) equals top left of screen mode.
I fixed the menu issue, and I got my character to use blending. The position isnt working though....
I made a function called Input() and this is what is inside
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = 1024; // set the width of the buffer
d3dpp.BackBufferHeight = 768; // set the height of the buffer
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3ddev);
//MainMenu Stuff
D3DXCreateSprite(d3ddev, &sprite);
D3DXCreateTextureFromFile(d3ddev, L"Menu.jpg", &mainmenutex);
D3DXCreateTextureFromFile(d3ddev, L"Battle.png", &battletex);
D3DXCreateTextureFromFileEx(d3ddev, // the device pointer
L"trainer.png", // the new file name
D3DX_DEFAULT, // default width
D3DX_DEFAULT, // default height
D3DX_DEFAULT, // no mip mapping
NULL, // regular usage
D3DFMT_A8R8G8B8, // 32-bit pixels with alpha
D3DPOOL_MANAGED, // typical memory handling
D3DX_DEFAULT, // no filtering
D3DX_DEFAULT, // no mip filtering
D3DCOLOR_XRGB(255, 255, 255), // the hot-pink color key
NULL, // no image info struct
NULL, // not using 256 colors
&chartex); // load to sprite
}
This is what you are passing in as the position parameter every frame. Regardless of what you do in Input() you are resetting position to (0,0,0) in Game() before your draw call every frame. What do you expect to happen?
You've made position a global, but you are resetting it to (0,0,0) literally the line before you call Draw(). This makes me suspect that continuing to advise on this is a bit pointless.
With the greatest respect and with the best intentions in the world, you simply can't blunder and guess your way through something as complex as a Direct3D-based graphics application. You need to step back and get some more fundamental programming concepts in your mind through simpler applications first.
I hope that isn't offensive in anyway. I don't mean it to be. I just think you've clearly tried to learn to swim by jumping from a helicopter into the middle of the pacific. In programming, it rarely works out that way but I wish you luck.