PhysicsPlatformer.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. scene = new Atomic.Scene();
  25. scene.createComponent("Octree");
  26. scene.createComponent("DebugRenderer");
  27. physicsWorld = scene.createComponent("PhysicsWorld2D");
  28. physicsWorld.continuousPhysics = false;
  29. physicsWorld.subStepping = false;
  30. cameraNode = scene.createChild("Camera");
  31. cameraNode.position = [0.0, 0.0, -10.0];
  32. camera = cameraNode.createComponent("Camera");
  33. camera.orthographic = true;
  34. camera.orthoSize = graphics.height * Atomic.PIXEL_SIZE;
  35. var viewport = new Atomic.Viewport(scene, camera);
  36. renderer.setViewport(0, viewport);
  37. // currently lightgroup must be created after viewport 0 is set
  38. lightGroupNode = scene.createChild("LightGroup");
  39. lightGroup = lightGroupNode.createComponent("Light2DGroup");
  40. lightGroup.setPhysicsWorld(physicsWorld);
  41. uiNode = scene.createChild("UI");
  42. uiNode.createJSComponent("UI");
  43. levelNode = scene.createChild("Level");
  44. levelNode.createJSComponent("Level");
  45. avatarNode = scene.createChild("Avatar");
  46. avatarNode.createJSComponent("Avatar");
  47. backgroundNode = scene.createChild("Background");
  48. backgroundNode .createJSComponent("Background");
  49. }