Comparison between XNA and DirectX (C#)

If you’re actually good at writing unmanaged code, then you’ll probably be able to write a faster graphics engine on top of DirectX. However, for the hobbyist, XNA has plenty of performance, both for 2D and 3D game development. Here is a good Channel 9 video where they run an XNA-built racing game on Xbox … Read more

Convert Kinect ColorImageFrame to Bitmap

You can find the answer in this article. To summarize it, this method should do the trick: Bitmap ImageToBitmap(ColorImageFrame img) { byte[] pixeldata = new byte[img.PixelDataLength]; img.CopyPixelDataTo(pixeldata); Bitmap bmap = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppRgb); BitmapData bmapdata = bmap.LockBits( new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, bmap.PixelFormat); IntPtr ptr = bmapdata.Scan0; Marshal.Copy(pixeldata, 0, ptr, img.PixelDataLength); bmap.UnlockBits(bmapdata); return … Read more

Convert string to Color in C#

Color red = Color.FromName(“Red”); The MSDN doesn’t say one way or another, so there’s a good chance that it is case-sensitive. (UPDATE: Apparently, it is not.) As far as I can tell, ColorTranslator.FromHtml is also. If Color.FromName cannot find a match, it returns new Color(0,0,0); If ColorTranslator.FromHtml cannot find a match, it throws an exception. … Read more

How to calculate bounce angle?

You might think that because your walls are aligned with the coordinate axes that it makes sense to write special case code (for a vertical wall, negate the x-coordinate of the velocity; for a horizontal wall, negate the y-coordinate of the velocity). However, once you’ve got the game working well with vertical and horizontal walls, … Read more