2017-07-06 12 views
0

setAttributeに問題があります。私はrotationの値としてArrayを設定しますが、動作しません。 gradRollのアラートはnumberです。しかし、gradRollのタイプはundefinedです。どうして?誰か助けてくれますか?前もって感謝します。js setAttribute with Array

AFRAME.registerComponent('clockhand_roll',{ 
    schema:{ 
     type:'string', default: "secondClockhand" 
    }, 

    init:function(){ 
     var data = this.data; 
     var el=this.el; 

     var oTime= new Date(); 
     var curTime; 

     var clockhandPositonArray; 

     if(data == "secondClockhand"){ 
     curTime = oTime.getSeconds(); 
     }else if(data == "minuteClockhand"){ 
     curTime = oTime.getMinutes(); 
     }else if(data == "hourClockhand"){ 
     curTime = oTome.getHours; 
     }else { 
     alert("invalid input!"); 
     } 

     //alert(curTime); 
     //clockhandPositonArray=getClockhandPosition(curTime, data); 
     //alert(el.getAttribute("rotation")); 

     //el.setAttribute("rotation", 'clockhandPositonArray'); 

     setClockhandPosition(el, curTime, data); 

    } 
    }); 

    function setClockhandPosition(el, curTime, typeOfClockhand){ 
    var gradForOneUnit; 
    var gradRoll; 
    var rotationArray; 

    if(typeOfClockhand == "secondClockhand" || typeOfClockhand == "minuteClockhand"){ 
     gradForOneUnit=360/60; 
    }else if(typeOfClockhand == "hourClockhand"){ 
     gradForOneUnit=360/12; 
    } 

    gardRoll=curTime*gradForOneUnit; 

    //alert(gardRoll); //number: 354!!!!!!!!!!!!!!!!!!!! why?????? 
    //alert(typeof(gradRoll)); //undefined!!!!!!!!!!!!! why?????? 

    rotationArray=[curTime*gradForOneUnit, 0, 0]; 

    //alert(typeof(rotationArray));//object 
    //alert(typeof(el.getAttribute("rotation"))); //object 

    //alert(rotationArray); //number: 162 , 0, 0 

    el.setAttribute("rotation", rotationArray); //dosn't work. 
    } 
+1

ルック ':
el.setAttribute("rotation", 'x'+'y' + 'z'); 方法は、私の知る限りでは、それはパース('x y z' to {x,y,z})を省略し、最初の場所でオブジェクトを使用するために、もう少し効率的ですgradRoll/gardRoll' –

+0

@Nathan P. thanks –

+0

rotationArray = {x:curTime * gradForOneUnit、y:0、z:0};それは動作します –

答えて

0

ロット:タイプミスのため
el.setAttribute("rotation", {x:gradRoll,y:0,z:0});

0

用途:

el.setAttribute("transform", "rotate3d,x,y,z,angle)"); 

またはrotateXrotateYrotateZを兼ね備えています。

+1

ありがとう。回転はオブジェクトでなければなりません。 –

0

gradRollは変数名がgardRollであるため定義されていません。これは最初のアラートで繰り返されたが2番目のアラートで繰り返されるタイプミスです。私はそれにタイプミスで変数を使用

el.setAttribute("rotation", gardRoll + ' 0 ' + '0'); 

注:

あなたが唯一の回転のX値を編集したいようなので、これを試しているようです。

私が知っているのはちょっと汚いですが、ポジションコンポーネントで同様の問題が発生したときにはうまくいきました。示唆人々の

+1

ありがとうございます。 –