《想到什麼更新什麼系列》processing 性能優化

·Image相關dom

image(img,x,y,width,height),圖片過多時會致使掉幀,能夠考慮在一開始的時候使用resize()方法進行縮放,而後顯示縮放後的圖片優化

void setup(){ img = loadImage("..."); } void draw(){ image(img,0,0,20,20); } || \/

void setup(){ img = loadImage("..."); img.resize(20,20); } void draw(){ image(img,0,0); }

 

·Shape相關spa

1.可以noStroke()的,儘可能noStroke(),畫布存在大量ellipse時,stroke的繪製會消耗大量計算。code

2.可以Ellipse的,儘可能不用point()blog

 

void setup(){ size(500,500); } void draw(){ background(255); noStroke(); fill(255,0,0); for(int i = 0 ; i < 5000; i ++){ circle(random(width),random(height),10); } surface.setTitle(frameRate + ""); } 對比: void setup(){ size(500,500); } void draw(){ background(255); strokeWeight(10); stroke(255,0,0); for(int i = 0 ; i < 5000; i ++){ point(random(width),random(height)); } surface.setTitle(frameRate + ""); }

 

 

 

 

·Sketch相關圖片

有時候加上P2D以後,你可能不須要考慮其餘優化問題了,雖然它有可能下降一些渲染精度。細節參照:https://processing.org/tutorials/rendering/ip

 

·語言相關ci

能用for的儘可能不用foreachit

能用[]儘可能不用Collectionsio

相關文章
相關標籤/搜索