{"id":73,"date":"2010-02-05T23:36:18","date_gmt":"2010-02-05T22:36:18","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=73"},"modified":"2010-02-05T23:36:18","modified_gmt":"2010-02-05T22:36:18","slug":"box2d-xna-great-2d-physics-engine","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2010\/02\/box2d-xna-great-2d-physics-engine\/","title":{"rendered":"Box2D.XNA : a great 2D physics engine"},"content":{"rendered":"<p>Box2D is a 2D physics engine created by Erin Catto. On Win\/Mac, I used a very early version of <a href=\"http:\/\/www.box2d.org\/\">Box2D<\/a> (it was released nearly two years ago!). I just made a few specific changes for the game. Of course, as I told in a <a href=\"http:\/\/www.frozax.com\/blog\/2009\/12\/win-mac-x360-differences-cplusplu-csharp\/\">previous article<\/a>, XNA games must be made in C# and Box2D is made in C++. I could find multiple open-source projects of ports of Box2D in C#. They are based on the last version of the C++ engine and a lot of changes occured since I developed Spring Up!.\u00a0 It means that to use a C# port, I have to adapt a lot of my physics code. But this is a good thing for the following reasons:<\/p>\n<ul>\n<li>I will have the new version of the engine : there are probably some debug and optimisations.<\/li>\n<li>New features : can be used to improve the game<\/li>\n<li>Lots of C# code already written, I won&#8217;t have to port it myself.<\/li>\n<\/ul>\n<p>Among the two or three C# ports available, I decided to go with <a href=\"http:\/\/box2dxna.codeplex.com\/\">Box2D.XNA<\/a>. This port is written by Brandon and Nathan Furtwangler and they are doing a very good job! They are very active: when I fixed them a bug, they put it back in the code base in less than a day and they port the changes of the C++ version very quickly.<br \/>\nCompared to the old C++ engine I was using previously, the new version has been greatly improved, here are some examples:<\/p>\n<ul>\n<li><strong>Dynamic\/Static\/Kinetic<\/strong> types are included on bodies, no need to play with infinite mass directly.<\/li>\n<li><strong>Collision filtering<\/strong> is now included in the API. I developed my own system in Spring Up! but throw it away in C#.<\/li>\n<li><strong>Motors <\/strong>are included. I also developed basic motors myself in C++.<\/li>\n<li>More <strong>joints <\/strong>types: only one type was available.<\/li>\n<li>Collision detection includes <strong>polygons<\/strong>, not just only circles and rectangles.<\/li>\n<\/ul>\n<p>As I&#8217;m still working with the level editor, I started to include new features in Spring Up! Here is a simple video showing a new possibility made with Box2D.XNA (showing motors, complex shapes, joints and collision detection).<br \/>\n<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"480\" height=\"295\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/Pf4ELAm7oug&amp;hl=fr_FR&amp;fs=1&amp;\" \/><param name=\"allowfullscreen\" value=\"true\" \/><embed type=\"application\/x-shockwave-flash\" width=\"480\" height=\"295\" src=\"http:\/\/www.youtube.com\/v\/Pf4ELAm7oug&amp;hl=fr_FR&amp;fs=1&amp;\" allowscriptaccess=\"always\" allowfullscreen=\"true\"><\/embed><\/object><br \/>\nAs you can see, the gameplay does not seem that interesting in this sample but it&#8217;s just made to test the dynamics for now. I will concentrate on level design later and I am sure I will face a lot of difficulties.<\/p>\n<p>In conclusion, if you need 2D physics in your game, use Box2D, and if it&#8217;s for XNA, use the Box2D.XNA port!<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F02%2Fbox2d-xna-great-2d-physics-engine%2F&amp;linkname=Box2D.XNA%20%3A%20a%20great%202D%20physics%20engine\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F02%2Fbox2d-xna-great-2d-physics-engine%2F&amp;linkname=Box2D.XNA%20%3A%20a%20great%202D%20physics%20engine\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F02%2Fbox2d-xna-great-2d-physics-engine%2F&amp;linkname=Box2D.XNA%20%3A%20a%20great%202D%20physics%20engine\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F02%2Fbox2d-xna-great-2d-physics-engine%2F&amp;linkname=Box2D.XNA%20%3A%20a%20great%202D%20physics%20engine\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Box2D is a 2D physics engine created by Erin Catto. On Win\/Mac, I used a very early version of Box2D (it was released nearly two years ago!). I just made a few specific changes for the game. Of course, as I told in a previous article, XNA games must be made in C# and Box2D&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2010\/02\/box2d-xna-great-2d-physics-engine\/\">Continue reading <span class=\"screen-reader-text\">Box2D.XNA : a great 2D physics engine<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,15,19,21],"tags":[59,106,137,141],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}