I’m new to DirectX and I am trying to get my feet wet by making a simple 2D game. I chose DirectX 11 and am using the DirectX ToolKit helper library from here: https://github.com/Microsoft/DirectXtk which recommended I start with 11 and not 12.
The guide I am following to create an animating sprite is working great except for when attempting to draw a single sprite from the sprite sheet I am seeing “ghosting” of other sprites behind it. I created the sprite sheet and saved it as a PNG and also as a BMP and it seems to happen either way.
Here is the sprite sheet I am using:
It is 336px width, 48px height, in 48px x 48px square sprites. If I render the entire sprite sheet, or if I render the first sprite (0,0,48,48), it looks fine, but if I attempt to render the 2nd, 3rd, 4th, etc. this is how it renders:
Here is the code I am using to load the PNG file as a texture:
ComPtr<ID3D11Resource> ponyIdleResource; DX::ThrowIfFailed( CreateWICTextureFromFile(_D3dDevice.Get(), L"assets/pony_idle.png", ponyIdleResource.GetAddressOf(), _Texture.ReleaseAndGetAddressOf()) ); ComPtr<ID3D11Texture2D> ponyIdleTexture; DX::ThrowIfFailed(ponyIdleResource.As(&ponyIdleTexture)); CD3D11_TEXTURE2D_DESC ponyIdleDesc; ponyIdleTexture->GetDesc(&ponyIdleDesc);
and here is the code I am using to draw:
_SpriteBatch->Begin(); RECT sourceRect; sourceRect.left = 48; sourceRect.top = 0; sourceRect.right = 96; sourceRect.bottom = 48; _SpriteBatch->Draw(_Texture.Get(), _ScreenPos, &sourceRect, Colors::White, 0, _Origin); _SpriteBatch->End();
If I pass the RECT in as 0,0,48,48, it looks fine. Is there some special way I need to format my image? I’ve tried it as both PNG and BMP.
- Neil Armstrong's widow found Apollo 11 mission artifacts in closet
- The full, oddly complex story behind Casey Affleck’s ‘Ghost Story’ costume
- Review: Elegiac and moving, 'A Ghost Story' will haunt you
- Sprites dance above Hurricane Matthew
- Hamilton County to return artifacts excavated from Strawtown park to Miami tribe
- Megachurch leader T.D. Jakes to sue Young Jeezy, Kendrick Lamar over sampled speech on 'Holy Ghost' remix
- Artist draws an animated future
- Sprite may be the best hangover remedy, scientists find
- Man dies when he jumps in front of F train; 2d man clipped by No. 1 train
- Weird NJ: The ghost of Exit 82