about 2 months ago - No comments
By extending your Service Container class, a very basic version of dependency injection can be implemented. We’ll implement two forms of dependency injection: constructor and property injection. We’ll start by defining the Injectable attribute. [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class InjectableAttribute : Attribute { } We’ll use this attribute to
about 2 months ago - No comments
My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I’d like to say that I’m working on version 2.0. In version 2.0 I’m going to make the code more event driven. The old code uses the Xna Game class
about 3 months ago - No comments
I decided to add progress bar to the Windows 7 Taskbar in my Timer app. I started by downloading and compiling the Windows API Code Pack in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines: using Microsoft.WindowsAPICodePack.Taskbar; to your using statements. When
about 5 months ago - No comments
Normally I use extension methods in C# to extend a library that I did not write and therefore I have no control over. There are situations where it makes sense to use extension methods for a library that you yourself are writing. For example, when you have interfaces in your library. You want to keep
about 1 year ago - No comments
When you need to calculate an angle from a Vector2 structure, you can use this piece of code: public static class Vector2Helper { public static float CalculateAngle(Vector2 v) { float angle = 0.0f; if(v != Vector2.Zero) { v.Normalize(); angle = (float)Math.Acos(v.Y); if(v.X < 0.0f) angle = -angle; } return angle; } } I used this
about 1 year ago - 3 comments
I’ve been talking with a guy on the creator forums lately about SpriteSheets and so I decided it might be a good idea to post my SpriteSheet class. It’s very simple. Only reads sprites from left to right and assumes all Sprites are the same width and height. #region Using using System; using Microsoft.Xna.Framework; using
about 1 year ago - No comments
I recently needed to write out Color(s) as an xml attribute. I wrote 2 methods to read and write the Color(s) as Hex strings. Here ya go: namespace Snow.Xna.Graphics { public static class ColorHelper { private static char[] _hexDigits = {’0′, ’1′, ’2′, ’3′, ’4′, ’5′, ’6′, ’7′, ’8′, ’9′, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’,
about 1 year ago - No comments
Nick Gravelyn has released an open source set of C# extension methods for use with Xna. See the post here for more information. http://www.nickontech.com/2008/12/new-open-source-project-time/