Jump to content
  • Advertisement
Sign in to follow this  
Ekim_Gram

[SOLVED]Drawing problems with C# and SdlDotNet

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

After about an hour of reading through the numerous examples that come with the SdlDotNet API, SimpleExample and ImageExample to be exact, and I've run into a problem of trying to construct my own little demo of just blitting a background and a little space ship that you can move with the arrow keys. I've got the following source:
using System;
using System.Drawing;

using SdlDotNet;

namespace SDL_Test
{
	public class App
	{
		private bool done;
		private const int height = 480;
		private const int width = 640;
		private int xPos, yPos;
		private Surface screen;

		public App()
		{
			Events.KeyboardDown += new KeyboardEventHandler(this.KeyDown);
			Events.Quit += new QuitEventHandler(this.Quit);
			screen = Video.SetVideoModeWindow(width, height);
			Video.WindowCaption = "C# with SDL.NET";
			done = false;
			xPos = 100;
			yPos = 200;
		}

		private void KeyDown(object sender, KeyboardEventArgs e)
		{
			switch (e.Key)
			{
				case (Key.Escape):
				{
					done = true;
					break;
				}
				case (Key.Q):
				{
					done = true;
					break;
				}
			}
		}

		private void Quit(object sender, QuitEventArgs e)
		{
			done = true;
		}
		
		public void Run()
		{
			Surface background = new Surface("images/bg.bmp");
			Surface spaceship = new Surface("images/ship.jpg");
			spaceship.TransparentColor = System.Drawing.Color.Magenta;  // R = 255 G = 0 B = 255
			spaceship.Transparent = true;

			while (done == false)
			{
				while(Events.Poll())
				{
				}
				screen.Blit(background, new Rectangle(new Point(0,0), background.Size));
				screen.Blit(spaceship, new Rectangle(new Point(xPos,yPos), spaceship.Size));
				screen.Flip();
			}
		}

		public static void Main()
		{
			App mainApp = new App();
			mainApp.Run();
		}
	}
}


And here are the images I'm using: bg.bmp ship.jpg The background blits and so does the ship but the magenta colored background is still visible save for some parts that are somehow missing. So basically its a space ship with magenta colored blots around it. I'm still pretty new to coding with SdlDotNet, it's a little hard to find a tutorial. And a full OOP approach is a lot different than procedural or using a custom wrapper class with C++. New language, new API, same old problems. [Edited by - Ekim_Gram on July 29, 2005 11:50:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
You probably shouldn't be using a jpg for your ship. Jpegs are lossy compression and there is no guarentee that the color before converting to jpeg is the same color as after. Probably what is happening is that some spots of your picture are still the correct color and disappear, but the rest have been shifter slightly to another color and stay. Try using a bmp (and make sure all of the background is the right color), and then move to a lossless format like gif.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!