Scene.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var game = Atomic.game;
  2. var node = self.node;
  3. var time = 12;
  4. function start() {
  5. var scene = game.scene;
  6. // Add light flickers
  7. var lightNodes = scene.getChildrenWithComponent("Light", true);
  8. for (var i = 0; i < lightNodes.length; i++) {
  9. lightNodes[i].createJSComponent("LightFlicker");
  10. }
  11. // create the procedural sky
  12. var pnode = scene.createChild();
  13. var procSky = self.procSky = pnode.createComponent("ProcSky");
  14. procSky.setDayTime(time);
  15. // add the roboman
  16. var spawnPoint = scene.getChild("PlayerInfoStart", true);
  17. var roboman = node.createChild("TheRoboMan");
  18. roboman.createJSComponent("RoboMan");
  19. if (spawnPoint) {
  20. roboman.position = spawnPoint.position;
  21. }
  22. var musicFile = game.cache.getResource("Sound", "Music/StoryTime.ogg");
  23. musicFile.looped = true;
  24. var musicNode = scene.createChild("MusicNode");
  25. var musicSource = musicNode.createComponent("SoundSource");
  26. musicSource.gain = .5;
  27. musicSource.soundType = Atomic.SOUND_MUSIC;
  28. musicSource.play(musicFile);
  29. }
  30. function update(timeStep) {
  31. time += timeStep * .08;
  32. self.procSky.setDayTime(time);
  33. }