Scene.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "atomic component"
  2. //Define a Scene component
  3. exports.component = function(self) {
  4. //we are attaching that component to the Scene, so we are sure that ours node is a scene
  5. var scene = self.node;
  6. var time = 12;
  7. self.start = function() {
  8. // Add light flickers
  9. var lightNodes = scene.getChildrenWithComponent("Light", true);
  10. for (var i = 0; i < lightNodes.length; i++) {
  11. lightNodes[i].createJSComponent("Components/LightFlicker.js");
  12. }
  13. // create the procedural sky
  14. var pnode = scene.createChild();
  15. self.procSky = pnode.createComponent("ProcSky");
  16. self.procSky.setDayTime(time);
  17. //Create music
  18. var musicFile = Atomic.cache.getResource("Sound", "Music/StoryTime.ogg");
  19. //Set it looped
  20. musicFile.looped = true;
  21. var musicNode = scene.createChild("MusicNode");
  22. var musicSource = musicNode.createComponent("SoundSource");
  23. musicSource.gain = .5;
  24. musicSource.soundType = Atomic.SOUND_MUSIC;
  25. musicSource.play(musicFile);
  26. }
  27. self.update = function(timeStep) {
  28. time += timeStep * .08;
  29. self.procSky.setDayTime(time);
  30. }
  31. }