Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

I have still been learning the in and outs of Unity for the past few weeks. I've been thinking that because I have not been making any regular posts on this site that I would start posting a series of quick unity tips as I learn of them.

Tip #1 - Prevent config dialog from showing when running your compiled game.

When you build your unity game using "File -> Build & Run" and then run the *.exe that was generated you will see a dialog pop up.

To prevent the configuration window from being shown select "File -> Build Settings..." in unity and click the "Player Settings" button at the bottom of the window. The Unity inspector window will contain a number of options. Find the drop down titled "Display Resolution Dialog" and set it to "Disabled". Rebuild your game and run the generated *.exe. No more dialog pop up!

Zider Revisited

Published 9/11/2011 by createdbyx in News | Programming

I've been making numerous updates to my Zider project over at codeplex. Other then that I have not been getting much done programming wise, been busy with other things.

GAH! Google is such phail, Bing is no better either. Been trying to find out how to use EF + SqlCe without having to specify any settings in my web.config.

Finally I found this page on unit testing that pointed be in the right direction.

And here is how to do it in code!

    public class testModel
        public int ID { get; set; }
        public int SomeID { get; set; }

    public class MyClass : System.Data.Entity.DbContext
        public MyClass() { }
        public MyClass(string filename) : base(filename) { }
        public DbSet TableTest { get; set; }
    public class HomeController : Controller

        public ActionResult Index()
            var path = this.Context.Server.MapPath("~/bin/");
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", path, "");
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
            var tmp = new MyClass("test.sdf");
            tmp.TableTest.Add(new testModel() { SomeID = 5 });

            return this.View(); 

XNA Issues

Published 10/31/2010 by createdbyx in News | Programming | XNA

Some of the issues I have been having with XNA are starting to bug me the more I think about them. I started writing this back at xna 3.1 launch but have only gotten around to posting it now.

Lack of types

First there is no RectangleF structure! WTF?!? XNA ver 4.0 is out and it still does not have a RectangleF type. What is so special about a having a RectangleF type? It would cut down on the number of type casting that is involved especially when working with the SpriteBatch class. I am making a 2D tiled map component and for a 100x100 size map there are like over 40,000 float -> int casts that can occour per rendered frame! 100x100 map is a very small map size! Why I am casting to int is because if I don't there are half pixel issues that arrise and I get gaps between tiles if I don't perform the cast. Which is rediculous because the reason I even have these issues in the first place is because of the way the SpriteBatch class accepts input for drawing sprites.

Lets put it this way SpriteBatch accepts a Rectangle type for specifying a position to render the sprite on screen. This is one of the Draw methods on the SpriteBatch class ...

public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color)
    Vector4 vector;
    vector.X = destinationRectangle.X;
    vector.Y = destinationRectangle.Y;
    vector.Z = destinationRectangle.Width;
    vector.W = destinationRectangle.Height;
    this.InternalDraw(texture, ref vector, false, ref sourceRectangle, color, 0f, ref vector2Zero, SpriteEffects.None, 0f);

As you can see the method stores the destinationRectangle parameter in a Vector4 type. So because my data is originally stored as floats if I use this draw method I have to cast my data to a Rectangle type that consists of integers. Then I call this method which will only turns around and stores that rectangle data back as a float! I am being forced to cast my data for no good reason simply because the xna team has not provided a RectangleF type. /facepalm /repeat  It's things like this that just drive me friggin nuts!

What in the hell kind of frackin logic would make the xna team think thay don't need RectangleF type in the xna framework is beyond me. But if it were up to me needless to say, that kind of BS would not be tolerated. A RectangleF structure should have been there since day one of XNA 1.0! Just the fact that I am having to make all these casts to int is making my code unnessesarily messy to read makes me frustrated. The only real reason I can think of to want to cast to int is if you are using DrawString and you want to enusure your text get rendered cleanly.

The ContentManager

The ContentManager.ReadAsset method is coded as protected so the only way to use it is to create a new class that inherits from the ContentManager class. Why do I want to call this method? Because It allows me to load game assest from disk again to get back a new instance of a object rather then using Content.Load<> which will cache the object after the first load call.  How hard is it to give users the option via  Load<T>(string assetName, bool doNotCache). In order for me to get around this I am using the fallowing code ...

public class ExtendedContentManager : ContentManager
    public ExtendedContentManager(IServiceProvider serviceProvider)
        : base(serviceProvider)

    public virtual T Load<T>(string assetName, bool doNotCache)
        if (doNotCache)
            return ReadAsset<T>(assetName, null);

        return base.Load<T>(assetName);

public static class ContentManagerExtenders
    public static T Load<T>(this ContentManager manager, string assetName, bool doNotCache)
        if (manager is ExtendedContentManager)
            return ((ExtendedContentManager)manager).Load<T>(assetName, doNotCache);

        return manager.Load<T>(assetName);

But I also have to remember to replace the content manager in my game constructor via this.Content = new ExtendedContentManager(this.Services); /shakeshead

Additionally the ContentManager does not allow you to unload individual resources. It only allows you to unload all the resources via the Unload method. This could be a very handy feature in terms of optimizing the speed when loading up a new game map. For example if the game was loading up a new map rather then unloading all the resources you could hold onto the currently loaded resources then track what resources are not required after loading the new map is complete. Then unload each individual resource that is not needed, so in terms of numbers if the next map and the previous map use 90% of the same resources that means that you could save 90% of the work required to re-read the resources off the disk. This scenario also makes sense in situations where you want the map to load dynamically as the player traverses that map.

3.1 & No Avatar support for windows

Here I am thinking wu hoo Avatars! Then 3.1 is released and I come to find out that avatars are only supported for the xbox360!  /ShakeFist /StartMakingCrudeShankFromBrokenGlass It's like come on, Really. Really? Srsly disappointing.

ICloneable shiftyness

From .net Reflector found in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\mscorlib.dll  mscorlib.dll used by windows phone 7 apps

internal interface ICloneable
    // Methods
    object Clone();

For all that is sane in this world, can someone please tell me WHY ICloneable is declared as internal for xna Windows phone 7 apps?!?!?  It's an interface. With one one method. And the people in charge declared it a internal. WTF?

*raises arms in the air dumbfounded.*

Who at Microsoft made the retarted decision to declare it as internal o.O.  The decision is just so utterly friggin stupid. You went through all the effort to write the code and make use of it. But rather then declaring it as public and maintaining increased portability between frameworks you have gone to the effort of trying to hide it. You have used it in over 100 objects from System.Drawing.Font to System.Array to System.Xml.XmlNode etc.

Imagine you work for Microsoft and your sitting in your office and you are building the Silverlight framework. Your probably not writing the framework from scratch or maybe just parts of it, so there is a lot of cut and paste and porting going on from previous .net framework implementations. Low and behold you get to the ICloneable interface.

At what point and for what possible reason could you have to change ICloneable from public to internal. Do you not understand the implications your actions will have? Was it the lead dev that made the decision? .NET frameworks have been around for ten years now, in each release there has been a conscious effort when porting and updating the framework to keep as much of the framework in tacked as possible. ICloneable has been a staple of .net since the beginning, and to have it exist in the framework as well as making use of it internally, without making it public automatically breaks compatibility for absolutely so reason. The decision to make ICloneable internal is one based on coding philosophy. And by doing that you immediately come into conflict with other peoples philosophies. Also philosophies change over time. But code doesn't. Thus it needs to be re-factored making more work for end users.  :(

If your philosify excludes the use of ICloneable then don't use it. But that doesn't mean the Microsoft dev team should impose there own coding philosophy on the masses of people that will be using the api. Introducing breaking changes because of coding philosophy is just bad mojo.

Making it public maintains compatibility and minimal re-factoring for the countless developers that will be using the framework and porting all sorts of code over to the framework. The implications of going from public to internal is drastic in my opinion. It's a brain fart. It's like a cancer in my brain. As hard as I try to come up with excuses why they declared it as internal I can't think of a single reason. As developers we deal in logic and logical systems all the time and declaring it internal is highly illogical to me. There are unspoken rules even in programming and it's like a give in that you would NOT declare ICloneable as internal.

State types lacking property setters

The decision to make setters private for various state types (GamePadState for example) is one based on coding philosophy, specifically the philosophy of the xna team. The xna team decided for everyone that they had no need for property setters on the GamePadState and other types in the xna framework.

It's not about the xna team's philosophy, it's about providing functionality for usage scenarios that the xna team CAN'T think of. No property setters on state objects are a prime example. What would be a usage scenario, game pad emulation via other devices. For example writing code that uses DirectInput to get user input from devices and mapping that input over to a GamePadState object. Any existing code that uses the xna input types can continue to do so and be oblivious that the state data is actually coming from a DirectInput device behind the scenes.

Non boolean button states

Who decided that that using a enumerator to represent a button state was a good idea?

GamePadState lastState;
var state = GamePad.GetState(PlayerIndex.One);
if (state.Buttons.A == ButtonState.Pressed)
    // do something

if (state.Buttons.A) // boolean detection would look like this
    // do something -> does not compile

// detect click
if(lastState.Buttons.A == ButtonState.Pressed & state.Buttons.A == ButtonState.Released)
    // clicked

// detect click if booleans were used
if (lastState.Buttons.A & !state.Buttons.A)
    // clicked -> also does not compile because ButtonState enum is not mark with [Flags] attribute

In the code example above you can see that xna uses a ButtonState to represent if a button is Pressed or Released. Not to mention there is twice as much code to write. Button states should have been represented by a boolean not an enumerator.


Everything I have mentioned is easily fixable if only there were a more direct communications line to the microsoft dev team(s). Instead we are delegated to the black hole that is MS Connect. I have posts on there from 3 years ago, yes 3 years ago! Some of my entries still are not responded to and some only get a few words back saying well look into it.

As far as I know and weather things have changed in the last few years, ms connect is not a mandatory job function for ms dev teams and is not tied into Microsoft's back end bug/feature tracking systems. It's voluntary, so who knows how often a dev team actually spends any real time there.

I get frustrated at times as you can see. It's Microsoft, it's like worse then pulling teef. *Teeth :) Xna rocks the casba but there are times I tell ya. "You wanna go to the moon!" :D Someone posted the comment "man back then domestic violence´╗┐ was hilarious.´╗┐" ROFLMAO It's funny cause it's true. :P

Some was asking me about my XMLDocContentProcessor project and I decided to do up a quick demo video of how to use it.

The great outdoors await

Published 8/23/2009 by createdbyx in Example | News | Programming | XNA

Well I'm off to go pick mushrooms. I should be back around mid october or so depending on how the season goes. I have turned comment moderation on while i'm away to try and help keep the riff raff from spamming comments while i'm away.

I have added a few Ohsai updates and provided a second download this time with source code. Keep in mind that it is still in the prototyping stages but there is an example project with a few demos that will give you an idea of where the project is heading.

Oh and I'd just like to express just how much I hate Blizzard. "Just when I thought I was out. They ... pull ... me ... back ... in!" Sigh, I just spent a few hours today reading about the new World of Warcraft expansion called Cataclysm, and all of the various changes that will be taking place. I don't know what it is about that game but I compare it to being on crack. I hate even the thought of spending endless hours playing the game just to aquire items and gear etc, but at the same time I have this strong desire to play it.

The problem comes in when I start loosing the ability to manage my time properly between fighting the urge to play the game, and just trying to stay focused on other priorities. I have basically lost a year of work with my programming projects already because of two  previous six month subscriptions. And when I think about it in those terms I think about how much work I could have gotten done on those projects. No other game has even come close the the level of adddiction I have towards this game.

I am not sure what I am trying to say at this point other then before I heard about the new expansion I had 99% garenteed myself that i was never going to renew my subscription to that game. I have always felt a sense of deep loss that I am missing out when I don't have a subscription. Now after reading about the expansion I have almost convinced myself that I am 90% garenteed to renew my subscription in november. It's a vicous cycle.

Also just as a side note, I gotta mention just how blind I am to spotting spelling mistakes on my website. For the longest time there have been glaring and obvious spelling errors and for some reason I just can't seem to spot them. O.o

And OMG Comment spam! I don't even advertise this site and I am getting hit by spammers. I think I may need to leave comment moderation on when I come back. :(

Site was temporarilly down for about 30 hours. Nothing was broken I just left it as it was so that godaddy could take a look at if it was anything on there end. I wrote a new extension for BlogEngine that would allow me to embed [ SILVERLIGHT ] tags in pages or posts and have the tag replaced with a silverlight html "<object" markup.

But if you visited the site yesterday you would have seen the error page stating that there was a compile error on line two ala "using System.Linq;". This error had me scratching my head. I double checked the settings under godaddy hosting control panel and iis7 and 2.0/3.0/3.5 were set properly. One thing I did notice was that on the error page that the command line that was being called and invoking the C# compiler was not making any references to the System.Linq assemblies. Which would explain the compilation error. ASP.NET is the one that is invoking the call to the C# compiler and if goddady supported 3.5 as they claim I don't understand why my extension would not be compiling.

It sucks because I also got around to writing a second extension for BlogEngine that tracks changes I make to the site weather I create new content/delete content or just update content on the site it logs everything. Then every so often when I want to make a new blog entry all I have to do is type [ CHANGELOG ] and presto a nicley formated categorized and bulleted list get embeded into the post and the log file gets cleared out. I wrote this extension because sometimes I tweak the site here and there or add a little bit of new content and forget to mention it in a blog post. With this extension all that get handled for me automatically. 

Unfortunatley I cannot use this extension either because it heavilly uses linq as well. *Sigh*

Something else that has me concerned is that DomainPeople the company that I have registered my domain name with is not letting me log into there site. So I tried there password recovery option and provided my domain name then clicked the "Get Password" button but it comes back as saying it can't find that domain.  O.o wtf? I have used DomainPeople as my registar for for over 7 years how could they not have a record of my domain. Even the WhoIs records show that is registered using DomainPeople. I submited a feedback form but am still waiting to hear back from them. Grrr

So all around these last few days have not been all that great.

Sigh it can be frustrating sometimes working on my various programming projects. My main solution I work with now consists of  94 projects. View Screenshot

Some of the projects could be considered "Done" but I have yet to upload them to this website and some are still only partially written or working. I have been wanting to create a series of video tutorials that walk through each project but I keep finding myself putting it off, partly because making videos can be very time consuming, and I tend to have too high of standards when making them, "Dam, I should not have said that", "I keep rambling on about off topic stuff", "Forgot to mention this or that feature", "Stupid lispy voice :P" etc etc

It will probably be a while (possible never) before I get around to making any of the videos.

Besides all that I have been doing more work with using xna and winforms and have created a simplfied version of the control then what microsoft has on the xna creators club web site. The reason I created a simplified version of the control is because I needed the control to integrate better with my level editing window. I have provided a preview image below of the control in use in my level editor. The source code can be downloaded here. (1.58 mb) (XNA 3.1)

Also something to keep in mind that VS.NET 2008 seems to have issues when the name of the control is the same as the namespace that it resides in. In the example project you may encounter a compile error in the TextForm.Designer.cs file on this line of code "this.xnaControl = new SimplifiedWinformControl.SimplifiedWinformControl();" just delete the namespace off the begining so that it reads like this "this.xnaControl = new SimplifiedWinformControl();". To avoid the error be sure to name your control something other then the namespace that it belongs to. Something else to remember is that if the control is resized larger then the main game windows backbuffer then the control will only display what it can.

public class SimplifiedWinformControl : Control
    private Game game;
    public Texture2D Texture { get; set; }
    private SpriteBatch spriteBatch;

    public Game Game
        get { return; }
            // hold onto the game reference
   = value;
            if ( == null) return;
            // create the sprite batch
            this.spriteBatch = new SpriteBatch(;

    /// <summary>
    /// Ignores WinForms paint-background messages. The default implementation
    /// would clear the control to the current background color, causing
    /// flickering when our OnPaint implementation then immediately draws some
    /// other color over the top using the XNA Framework GraphicsDevice.
    /// </summary>
    protected override void OnPaintBackground(PaintEventArgs pevent)
        // do nothing here. If this is not overridden the control may have drawing issues O.o 

    protected override void OnPaint(PaintEventArgs e)
        if ( == null)
            // draw normal winform way
            e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, this.ClientRectangle);
            e.Graphics.DrawString(this.GetType().FullName, this.Font,
                                    System.Drawing.SystemBrushes.ControlText, 0, 0);
            // draw xna way 
            var gr =;
            var oldVP = gr.Viewport;

            // set the graphics viewport to the size the the controls client area
            var newVP = new Viewport()
                Width = this.ClientSize.Width,
                Height = this.ClientSize.Height,
                MinDepth = 0,
                MaxDepth = 1

            gr.Viewport = newVP;

            // clear then draw something onto the control
            this.spriteBatch.Draw(this.Texture, Vector2.Zero, Color.White);

            // display it onto the control
                var rect = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
                gr.Present(rect, null, this.Handle);
            catch (Exception)
                // Present might throw if the device became lost while we were
                // drawing so we just swallow the exception.

            // restore previous viewport
            gr.Viewport = oldVP;

    protected override void OnCreateControl()
        // check if we are not in design mode and if not hook into the application idle event
        if (!this.DesignMode)
            // just invalidate the control so that it will be redrawn
            // you could also put in some logic to restrict how often the control get invalidated
            Application.Idle += ((sender, e) => { this.Invalidate(); });

    // not really nessary in this simple example to have a dispose here but i put it in anyway
    protected override void Dispose(bool disposing)
        // perform some cleanup
        if (this.spriteBatch != null) this.spriteBatch.Dispose();
        this.spriteBatch = null;
        // we dont need to dispose of the texture here but I did anyway it will be
        // disposed by the content manager. :P But if you have texture(s) you created 
        // your self then this is where they would get disposed
        if (this.Texture != null) this.Texture.Dispose();
        this.Texture = null;

XNA WinForms Reduex!

Published 6/15/2009 by createdbyx in News | Programming | XNA

First start a new xna window game project. Then add a new "MDI Parent Form" to the project. After that change the code in the Program.cs file to look like this ...

static void Main(string[] args)

    using (Game1 game = new Game1())
        MDIParent1 mainMDIForm = new MDIParent1();
        var gameWindow = Control.FromHandle(game.Window.Handle) as Form;
        if (gameWindow != null)
            gameWindow.MdiParent = mainMDIForm;


Now press F5 to run the application. Voila! You can now proceed to add game editing or other win form controls to the MDI window for what ever you need. But some initial testing raised a few minor issues.

The first one is that once in a while the viewport does not get updated if the game window is resized. There is also a issue where keyboard keys don't work properly if the game window is the active window. To over come this just make sure that after you are finished interacting with the game window to just deactivate the window again. Then you will be able to press Alt-F to bring up the file menu for example.

Winforms in XNA

Published 6/1/2009 by createdbyx in Example | News | Programming | XNA

I have created a example project on the XNA page that demonstrates how to add winform controls to your game window in just a few lines of code. I created this project because I recently downloaded the winforms example project found at the XNA creators club website and found it to be rather overkill for what it does.  View Screenshot

Download the example project here. (38.58 kb) (XNA 3.0)

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume