Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ module.exports.AScene = registerElement('a-scene', {
this.object3D = new THREE.Scene();
this.render = bind(this.render, this);
this.systems = {};
this.systemNames = [];
this.time = 0;
this.init();
}
},

init: {
value: function () {
this.behaviors = { tick: [], tock: [] };
this.behaviors = {tick: [], tock: []};
this.hasLoaded = false;
this.isPlaying = false;
this.originalHTML = this.innerHTML;
Expand Down Expand Up @@ -141,6 +142,7 @@ module.exports.AScene = registerElement('a-scene', {
value: function (name) {
if (this.systems[name]) { return; }
this.systems[name] = new systems[name](this);
this.systemNames.push(name);
}
},

Expand Down Expand Up @@ -509,20 +511,23 @@ module.exports.AScene = registerElement('a-scene', {
*/
tick: {
value: function (time, timeDelta) {
var i;
var systems = this.systems;

// Animations.
TWEEN.update();

// Components.
this.behaviors.tick.forEach(function (component) {
if (!component.el.isPlaying) { return; }
component.tick(time, timeDelta);
});
for (i = 0; i < this.behaviors.tick.length; i++) {
if (!this.behaviors.tick[i].el.isPlaying) { continue; }
this.behaviors.tick[i].tick(time, timeDelta);
}

// Systems.
Object.keys(systems).forEach(function (key) {
if (!systems[key].tick) { return; }
systems[key].tick(time, timeDelta);
});
for (i = 0; i < this.systemNames.length; i++) {
if (!systems[this.systemNames[i]].tick) { return; }
systems[this.systemNames[i]].tick(time, timeDelta);
}
}
},

Expand All @@ -533,18 +538,20 @@ module.exports.AScene = registerElement('a-scene', {
*/
tock: {
value: function (time, timeDelta) {
var i;
var systems = this.systems;

// Components.
this.behaviors.tock.forEach(function (component) {
if (!component.el.isPlaying) { return; }
component.tock(time, timeDelta);
});
for (i = 0; i < this.behaviors.tock.length; i++) {
if (!this.behaviors.tock[i].el.isPlaying) { continue; }
this.behaviors.tock[i].tock(time, timeDelta);
}

// Systems.
Object.keys(systems).forEach(function (key) {
if (!systems[key].tock) { return; }
systems[key].tock(time, timeDelta);
});
for (i = 0; i < this.systemNames.length; i++) {
if (!systems[this.systemNames[i]].tock) { return; }
systems[this.systemNames[i]].tock(time, timeDelta);
}
}
},

Expand Down