PhysicsPlatformer.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. cache = GetResourceCache();
  2. graphics = GetGraphics();
  3. renderer = GetRenderer();
  4. engine = GetEngine();
  5. input = GetInput();
  6. ui = GetUI();
  7. gameui = GetGameUI();
  8. var halfWidth = graphics.width * Atomic.PIXEL_SIZE * 0.5;
  9. var halfHeight = graphics.height * Atomic.PIXEL_SIZE * 0.5;
  10. var enableDebugHud = false;
  11. function Start() {
  12. if (enableDebugHud) {
  13. var uiStyle = cache.getResource("XMLFile", "UI/DefaultStyle.xml");
  14. var debugHud = engine.createDebugHud();
  15. debugHud.defaultStyle = uiStyle;
  16. debugHud.toggleAll();
  17. }
  18. CreateScene();
  19. }
  20. function Update() {
  21. // physicsWorld.drawDebugGeometry();
  22. }
  23. function CreateScene() {
  24. daytime = false;
  25. scene = new Atomic.Scene();
  26. scene.createComponent("Octree");
  27. scene.createComponent("DebugRenderer");
  28. physicsWorld = scene.createComponent("PhysicsWorld2D");
  29. physicsWorld.continuousPhysics = false;
  30. physicsWorld.subStepping = false;
  31. cameraNode = scene.createChild("Camera");
  32. cameraNode.position = [0.0, 0.0, -10.0];
  33. camera = cameraNode.createComponent("Camera");
  34. camera.orthographic = true;
  35. camera.orthoSize = graphics.height * Atomic.PIXEL_SIZE;
  36. var viewport = new Atomic.Viewport(scene, camera);
  37. renderer.setViewport(0, viewport);
  38. // currently lightgroup must be created after viewport 0 is set
  39. lightGroupNode = scene.createChild("LightGroup");
  40. lightGroup = lightGroupNode.createComponent("Light2DGroup");
  41. lightGroup.setPhysicsWorld(physicsWorld);
  42. if (daytime)
  43. lightGroup.ambientColor = [1, 1, 1, 1];
  44. else
  45. lightGroup.ambientColor = [.8, .8, .8, .25];
  46. if (daytime)
  47. {
  48. TheSun = scene.createComponent("DirectionalLight2D");
  49. TheSun.color = [1, 1, 1, 0.15];
  50. TheSun.castShadows = true;
  51. TheSun.numRays = 1024;
  52. TheSun.backtrace = false;
  53. lightGroup.addLight(TheSun);
  54. }
  55. uiNode = scene.createChild("UI");
  56. uiNode.createJSComponent("UI");
  57. levelNode = scene.createChild("Level");
  58. levelNode.createJSComponent("Level");
  59. avatarNode = scene.createChild("Avatar");
  60. avatarNode.createJSComponent("Avatar");
  61. backgroundNode = scene.createChild("Background");
  62. backgroundNode .createJSComponent("Background");
  63. }