   D3DX10_SPRITE drawing problems
  I was wondering if anyone knew why my sprite is calculated with such giant matrix numbers and drawn off the screen.  In my original constructor for the sprite, I initialize the sprite, set the translation and scaling matrix's, set the matWorld to both matrix's multiplied together and it draws fine.  If i change the code around and try to set the position using a method, it somehow set the position to a huge number and doesnt fit on the screen.This is the original code that actually draws the spritebasicSprite::basicSprite(LPCSTR fileName, ID3D10Device* originDevice, float xPos, float yPos){// Point the device to the original devicedevice = originDevice;// Create the texture2D for the spritetexture = GetTexture2DFromFile(fileName);// Create the texture2D description structD3D10_TEXTURE2D_DESC desc;texture-&gt;GetDesc(&desc);// Clear out the shader resource viewD3D10_SHADER_RESOURCE_VIEW_DESC SRViewDesc;ZeroMemory(&SRViewDesc, sizeof(SRViewDesc));// Set the texture formatSRViewDesc.Format = desc.Format;// Set the type of resourceSRViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;SRViewDesc.Texture2D.MipLevels = desc.MipLevels;//Create the Shader Resource Viewdevice-&gt;CreateShaderResourceView(texture, &SRViewDesc, &SRView);// Set the sprites shader resource viewD3DSprite.pTexture = SRView;// Top left coordinates in U,V coordinatesD3DSprite.TexCoord.x = 0;D3DSprite.TexCoord.y = 0;// Determine the texture size in U,V coordinatesD3DSprite.TexSize.x = 1.0f;D3DSprite.TexSize.y = 1.0f;// Set the texture indexD3DSprite.TextureIndex = 0;// The color to apply to the spriteD3DSprite.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);// Fill the Sprite struct with information about location and scalingInformation.spritePosX = xPos;Information.spritePosY = yPos;Information.spriteWidth = desc.Width;Information.spriteHeight = desc.Height;// Create the translation matrixD3DXMatrixTranslation(&matrixTranslation, xPos, yPos, 0.1f);// Scale the sprite to its correct width and heightD3DXMatrixScaling(&matrixScaling, desc.Width, desc.Height, 0.1f);// Set the sprites position and sizeD3DSprite.matWorld = (matrixScaling * matrixTranslation);}For some reason when I change the code to this, it gives me a huge number for the position of the spritebasicSprite::basicSprite(LPCSTR fileName, ID3D10Device* originDevice){// Point the device to the original devicedevice = originDevice;// Create the texture2D for the spritetexture = GetTexture2DFromFile(fileName);// Create the texture2D description struct//D3D10_TEXTURE2D_DESC desc;texture-&gt;GetDesc(&desc);// Clear out the shader resource viewD3D10_SHADER_RESOURCE_VIEW_DESC SRViewDesc;ZeroMemory(&SRViewDesc, sizeof(SRViewDesc));// Set the texture formatSRViewDesc.Format = desc.Format;// Set the type of resourceSRViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;SRViewDesc.Texture2D.MipLevels = desc.MipLevels;//Create the Shader Resource Viewdevice-&gt;CreateShaderResourceView(texture, &SRViewDesc, &SRView);// Set the sprites shader resource viewD3DSprite.pTexture = SRView;// Top left coordinates in U,V coordinatesD3DSprite.TexCoord.x = 0;D3DSprite.TexCoord.y = 0;// Determine the texture size in U,V coordinatesD3DSprite.TexSize.x = 1.0f;D3DSprite.TexSize.y = 1.0f;// Set the texture indexD3DSprite.TextureIndex = 0;// The color to apply to the spriteD3DSprite.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);// Fill the Sprite struct with information about location and scalingscaleInfo.spriteWidth = desc.Width;scaleInfo.spriteHeight = desc.Height;// Create the translation matrixD3DXMatrixTranslation(&matrixTranslation, 0, 0, 0.1f);// Scale the sprite to its correct width and heightD3DXMatrixScaling(&matrixScaling, scaleInfo.spriteWidth, scaleInfo.spriteHeight, 0.1f);// Set the sprites position and sizeD3DSprite.matWorld = (matrixScaling * matrixTranslation);}void basicSprite::setPosition(float xPos, float yPos){// Set the position of the spriteD3DXMatrixTranslation(&matrixTranslation, xPos, yPos, 0.1f);D3DSprite.matWorld = (matrixTranslation * matrixScaling);}
Looking for an idea for a game? Why not try taking a peek at some old ones? Gamasutra looks at five not-quite-classics that had interesting ideas mucked up by poor execution, and uncovers how they just might work as present day indies.  View the full article