From 9decc7cac11a95c98ed352d7bb18b4eebb59cfd1 Mon Sep 17 00:00:00 2001 From: Maksims Mihejevs Date: Thu, 30 Jul 2015 18:15:07 +0100 Subject: [PATCH] fix light change type --- src/framework/components/light/light_system.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/framework/components/light/light_system.js b/src/framework/components/light/light_system.js index 0acbbd06776..ba44b1af71b 100644 --- a/src/framework/components/light/light_system.js +++ b/src/framework/components/light/light_system.js @@ -72,6 +72,7 @@ pc.extend(pc, function () { var light = new pc.Light(); light.setType(lightTypes[data.type]); light._node = component.entity; + light._scene = this.app.scene; this.app.scene.addLight(light); component.data.light = light; @@ -107,7 +108,17 @@ pc.extend(pc, function () { }, changeType: function (component, oldValue, newValue) { - component.light.setType(lightTypes[newValue]); + // remove old light + this.app.scene.removeLight(component.light); + // create new light + var light = new pc.Light(); + light.setType(lightTypes[newValue]); + light._node = component.entity; + // add to scene + this.app.scene.addLight(light); + // add to component + component.light = light; + component.data.light = light; } });