2016-06-12 21 views
1

我很新的BabylonJS和我創建了一個自定義的網一樣,(我不知道這是否是正確的方式):Javascript方法在BabylonJS不工作與自定義網

function DragSphere() { 
    this.sphere = BABYLON.Mesh.CreateSphere("sphere", 15, 2, scene); 
    this.sphere.material = new BABYLON.StandardMaterial("sphereMat", scene); 
    ... 
    return (this.sphere); 
} 

DragSphere.prototype.setRGBColor = function(r, g, b) { 
    this.sphere.material.diffuseColor = new BABYLON.Color3(r/255, g/255, b/255); 
} 

所以我想用我的DragSphereSetRGBColor方法來更新它的顏色,但是瀏覽器似乎並不同意我:

Uncaught TypeError: sphere.setRGBColor is not a function 

回答

1

從構造函數中刪除return (this.sphere);聲明。

如果您使用的是TypeScript,則只能使用new運算符調用void函數。如上所述,在返回類型中使用返回類型調用函數將導致setRGBColor函數在傳輸的JavaScript中未定義。

您可以在Babylon JS playground中試用。

+0

嗨,thx的響應,但我沒有使用TypeScript ^^ –

+0

好吧 - 同樣適用於JavaScript(雖然我不認爲你總是得到在構造函數返回錯誤消息)。你有沒有嘗試刪除返回語句? @boehm_s – Mark

+0

我會試試這個,因爲我的項目在另一臺電腦上,謝謝;) –

相關問題