• 15
• 15
• 11
• 9
• 10

# Having trouble with sprites with Managed DirectX

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I've recently been fiddling around with SDL.NET. Because of lack of documentation for SDL.NET ( Yes I know I can use the old C documentation, but it's not comfortable) I decided to port my *very* simple sprite drawing program to Managed DirectX. I am having trouble, which, unfortunately, I can't find the cause of. So, sorry for my question being vague or not direct enough, cause I don't know where the source of my problem is. So, please take a look at some of my code.
private void init_sprites()
{
TankArrayList = new ArrayList();
int i;

for (i = 0; i<=31;i++)
{
//	try
//	{
//hakk til að fá rétt marga tölustafi
if(i<10)
{
TankSpriteTexture = TextureLoader.FromFile(device, @"C:\Documents and Settings\hallgrimur\My Documents\Visual Studio Projects\directxleikur1\images\green tank bitmaps\tank groundpart000"+ i + ".bmp");

}
else
{
TankSpriteTexture = TextureLoader.FromFile(device, @"C:\Documents and Settings\hallgrimur\My Documents\Visual Studio Projects\directxleikur1\images\green tank bitmaps\tank groundpart00"+ i + ".bmp");
//Logger.Append(tankImage.Transparent.ToString(),Logger.Priority.INFO);
}

//	}
//	catch(System.IO.IOException e)
//	{
//fuck
//	}
}

using (Surface s = TankSpriteTexture.GetSurfaceLevel(0))
{

SurfaceDescription desc = s.Description;
textureSize = new Rectangle(0, 0, desc.Width, desc.Height);
}


What I have noticed is, for instance, that desc.Width and desc.Height is = 256, my sprite (.bmp) is 160x160. Ok, some more code...
	public void Draw()
{
TankSprite.Begin(SpriteFlags.None );
TankSprite.Draw((Texture)TankArrayList[tank_index],textureSize,Center,position,Color.Black);
TankSprite.End();
}


I don't really see anything wrong with this. I only update tank_index with my arrow keys; for instance, pressing right arrow key will increment tank_index and therefore use a sprite (of a tank) which has the tank slightly rotated to the right. And finally... my OnPaint function:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target, System.Drawing.Color.CornflowerBlue, 1.0f, 0);

tank.Draw();
device.Present();

}


The result is I get a screen filled with the CornflowerBlue color, no tank is displayed. I'm sorry if this sounds stupid, I'm only a beginner :). Thanks alot for your time... Oh, I'm using Managed Directx 9 Kick Start: Graphics and Game Programming as reference.