PageRenderTime 17ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/js/DemoBox2D/DemoBox2DApp.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 44 lines | 19 code | 3 blank | 22 comment | 3 complexity | ef327361794feeef6a33094c0f87d412 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. File:
  3. DemoBox2DApp.js
  4. Created By:
  5. Mario Gonzalez
  6. Project:
  7. RealtimeMultiplayerNodeJS
  8. Abstract:
  9. This is the core module for the DemoBox2DApp contains the namespace
  10. This demo shows how to create a game that uses a Box2D javascript implementation (https://github.com/HBehrens/box2d.js)
  11. Basic Usage:
  12. This class is not instantiated
  13. Version:
  14. 1.0
  15. */
  16. DemoBox2D = (typeof DemoBox2D === 'undefined') ? {} : DemoBox2D;
  17. /**
  18. * Allows a package to create a namespace within RealtimeMultiplayerGame
  19. * From Javascript Patterns book
  20. * @param ns_string
  21. */
  22. DemoBox2D.namespace = function (ns_string) {
  23. var parts = ns_string.split('.'),
  24. parent = DemoBox2D,
  25. i = 0;
  26. // strip redundant leading global
  27. if (parts[0] === "DemoBox2D") {
  28. parts = parts.slice(1);
  29. }
  30. var len = parts.length,
  31. aPackage = null;
  32. for (i = 0; i < len; i += 1) {
  33. var singlePart = parts[i];
  34. // create a property if it doesn't exist
  35. if (typeof parent[singlePart] === "undefined") {
  36. parent[singlePart] = {};
  37. }
  38. parent = parent[singlePart];
  39. }
  40. return parent;
  41. };