8. 优化数学计算
比如,如果可以避免使用浮点型(float),尽量使用整形(int),尽量少用复杂的数学函数比如 Sin 和 Cos 等等。
1、 ArrayList的对象在使用时应该注意以下事项
使用
arraylen = myarray. length;
for (i=0; i< arraylen; i++)
{
}
避免
for (i=0; i<myarray.length; i++) {
}
2、 少用临时变量
使用
var touch:Vector2;
function Update(){
if (count==0) { touch=iPhone.GeTouch(0).position;}
}
避免
function Update(){
if (count==0) {
var touch:Vector2=iPhone.GeTouch(0).position;
}
}
3、 少用算数符号/,改为乘以相应小数
使用
x * 0.5f
避免
x/2
4、 动作和AI不需要每帧都执行
if (GLO.count%3){
// execute the enemy aim at your player every 3 Update
}
if (GLO.count%5){
// execute player IA every 5 Update
}