Loading Sprites with DirectX - VS2005
Author |
Message |
chrisciscoioio
|
Posted: Sat Nov 17, 2007 1:00 pm Post subject: Loading Sprites with DirectX - VS2005 |
|
|
SOLVED.
Hello,
Let me first be less vague in the title, I cannot pull what I really need in such a small space.
Basicly, I am creating a 'simple' 2D Engine Layout to test AI theories.
Now I have the tiles loading, and that works fine, my problem comes when loading the player character
(aka Mario, I found on the web) and loading the AI character(s) (aka Luigi, I also found and borrowed off the web).
I use a simple RECT to grab each of the 12 frames, after countless debugging steping through the values are correct.
SPRITE* pSprite comes from a Struct, which you can find in the source code zip I have uploaded.
code: |
void DrawSprite(SPRITE* pSprite, int Frame, float x, float y, float z)
{
RECT FrameBox;
FrameBox.left = (Frame / pSprite->cols) * pSprite->width; // Specifies the x-coordinate of the upper-left corner of a rectangle.
FrameBox.top = (Frame / pSprite->cols) * pSprite->height; // Specifies the y-coordinate of the upper-left corner of a rectangle.
FrameBox.right = FrameBox.left + pSprite->width; // Specifies the x-coordinate of the lower-right corner of a rectangle.
FrameBox.bottom = FrameBox.top + pSprite->height; // Specifies the y-coordinate of the lower-right corner of a rectangle.
D3DXVECTOR3 position(x, y, z);
d3dspt->Draw(pSprite->tex, &FrameBox, NULL, &position, D3DCOLOR_XRGB(255, 255, 255));
return;
}
|
The image also loads fine, because you can see it, but it becomes Stretched and some of it gets cut off, from either the right or left side.
This is the function call which calls the DrawSprite, which you can see above.
This sets it to display at 100,100 with a z-index of 1, on top of terrain, it will display Frame 1.
code: | DrawSprite(&unit[1], 1, 100, 100, 1); |
The values of Frame on in the image are for the RECT
left - 0
top - 0
right - 24
bottom 32
Which is correct.
---
Edit:
I should also add that from what I have tested, changing the image type or settings, as well as changing the editor makes no difference from what I have tryed.
I have tryed:
16 colour bmp
256 color bmp
16-bit bmp
jpg
png
With editors:
GIMP
Paint
---
Yet the image still does not display correctly
I have attached all the source code, and it is with VS2005
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Engine.zip |
Filesize: |
4.04 MB |
Downloaded: |
174 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|