Jump to content
  • Advertisement
Sign in to follow this  
Ekim_Gram

More TextSprite problems - Updating text

This topic is 4839 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

Prior to posting this, I constructed the following example for easier explanation:
using System;
using System.Drawing;

using SdlDotNet;
using SdlDotNet.Sprites;

namespace SDL_Test
{
	public class App
	{
		#region properties
		private bool done;
		private const int height = 480;
		private const int width = 640;
		public int number = 0;
		public SdlDotNet.Font font;
		private Surface screen;
		public TextSprite text;
		#endregion

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

		#region events
		private void Keyboard(object sender, KeyboardEventArgs e)
		{
			switch (e.Key)
			{
				case (Key.Escape):
					done = true;
					break;

				case (Key.Q):
					done = true;
					break;

				case (Key.UpArrow):
					if (e.Down)
					{
						number++;
						string myString = Convert.ToString(number);
						text.Surface = font.Render(myString, System.Drawing.Color.White);
					}
					break;
			}
		}

		private void Quit(object sender, QuitEventArgs e)
		{
			done = true;
		}
		#endregion
		public void Run()
		{
			Surface background = new Surface("images/pong_background.bmp");
			SpriteCollection myCollection = new SpriteCollection();
			font = new SdlDotNet.Font("FreeSans.ttf", 32);
			text = new TextSprite((Convert.ToString(number)), font, System.Drawing.Color.White, new Vector(100, 0));
			myCollection.Add(text);
			while (done == false)
			{
				while(Events.Poll())
				{
				}
				screen.Blit(background, new Rectangle(new Point(0,0), background.Size));
				screen.Blit(myCollection);
				screen.Flip();
			}
		}

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

My problem is that whenever I press the upArrow, the text does not change. Here's the catch though, it works on normal surfaces. I'm guessing it's maybe another bug? Unless I'm doing something wrong that is.

Share this post


Link to post
Share on other sites
Advertisement
TextSprite needs a lot more work. You shouldn't ever be able to manipulate the surface at all, in my opinion.

Try using this instead:
case (Key.UpArrow):
number++;
text.TextString = number.ToString();
break;

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!