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
证明是在布丁。一般来说,在合理的时间间隔内对用户的不断输入进行采样是可以接受的做法,但是您是否应该这样做的答案在于您尝试时会发生什么。 – HackedByChinese 2012-02-28 12:56:25
到目前为止抽样一直没有问题 - 我只是担心数组[链接](http://mindprints.org) – Mindprints 2012-02-29 08:16:02