2012-02-28 87 views
1

爲了精確定位鼠標座標非常不穩定的對象,我跳過了一兩步,而且豪華地使用了大量的向量索引。但這是否意味着我在向量中分配了6000個左右的值?它會減慢某些東西嗎?還是可以嗎?JavaScript陣列效率

// ---- starting position ---- 
    mouse.x  = screen.w/2; 
    mouse.xd  = mouse.x; 
    camera.x  = scene.startX || 0; 
    camera.z  = scene.startZ || 0; 
    camera.targetX = scene.targetX || 0; 
    camera.targetZ = scene.targetZ || 0; 
    var picIndex=new Array(1,101,2101,4101,4401,5401,6401,6301,2301,2001); // pics position in room 
    var myPics=new Array(); // 
    myPics[1]="This is picture 1"; // 
    myPics[101]="This is picture 2"; 
    myPics[2101]="This is picture 3"; 
    myPics[4101]="This is picture 4"; 
    myPics[4401]="This is picture 5"; 
    myPics[5401]="This is picture 6"; 
    myPics[6401]="This is picture 7"; 
    myPics[6301]="This is picture 8"; 
    myPics[2301]="This is picture 9"; 
    myPics[2001]="This is picture 10"; 


    // then show picture identification 


    setInterval(function() { 
    uniqueID = (camera.targetZ*2)+camera.targetX+3201; 
    showInfo = document.getElementById('dynamic_info'); 
    showInfo.innerHTML = myPics[uniqueID] ; 
     //document.getElementById('dynamic_info2').innerHTML = camera.targetX ; 
     //document.getElementById('dynamic_info3').innerHTML = uniqueID; 
     //document.getElementById('dynamic_info4').innerHTML = camera.z ; 
     //document.getElementById('npoly').innerHTML = npoly * 2; 
     //fps = 0; 
     //npoly = 0; 
    }, 500); // update every 0.5 seconds 
+0

證明是在布丁。一般來說,在合理的時間間隔內對用戶的不斷輸入進行採樣是可以接受的做法,但是您是否應該這樣做的答案在於您嘗試時會發生什麼。 – HackedByChinese 2012-02-28 12:56:25

+0

到目前爲止抽樣一直沒有問題 - 我只是擔心數組[鏈接](http://mindprints.org) – Mindprints 2012-02-29 08:16:02

回答