1、当分析你的程序效能时,始终保证没有其他的Flash程序正在运行,因为它们可能会破坏你的指标。 随着CPU的使用率,预想它超过90的时候动画屏幕就黑屏了例如,如果您切换到另一个浏览器选项卡或向下滚动页面。较低的帧频导致它不会引起CPU密集型任务,但闪存节流下来的帧频无论每当你在看哪里。每当发生这种情况,等待几秒钟后的CPU使用率图,在正常的帧频开始工作后来使恢复到合适的CPU使用率值。 步骤二:这种代码会使我的flash看起来很“肥”吗? 下面是动画影片的源代码,它只有一个类,叫Flames,也是文档类。这个类包含了一些属性来追踪影片内存使用和CPU使用率历史,被用来画一个图表。内存和CPU使用
2、率数据的计算和更新都是在Flames.getStates() 这个函数中,并且图表是由Flames.drawGraph()逐帧绘制的,为了创造火焰效果,Flames.createParticles()这个函数首先每秒生成几百个粒子,粒子都被存储在fireParticles这个数组里。这个数组在Flames.drawParticles()中不断循环,用粒子属性创造效果。 花一点时间研究一下Flames这个类。你已经意识到任何迅速的变化在优化程序上还有很长的路要走吗?1. Packagecom.pjtops 2. Importflash.display.MovieClip; 3. Importfl
3、ash.events.Event;4. Importfl.motion.Color;5. Importflash.geom.Point;6. Importflash.geom.Rectangle;7. Importflash.text.TextField;8. Importflash.system.System;9. Importflash.utils.getTimer;10. 11. PublicclassFlamesextendsMovieClip 12. 13. PrivatevarmemoryLog=newArray();/storesSystem.totalMemoryvaluesf
4、ordisplayinthegraph14. Max0;highestvalueofrecordedsofar 15. Minlowest16. Color;colorusedbytextdisplayinginfo 17. 18. tickscountsnumbertimesgetStats()iscalledbeforenextframerateset 19. frameRate/theoriginalassetAdobeFlash 20. cpuLogcpugraph 21. cpuMax22. cpuMin23. cpuColor;cpu 24. cpu;currentcalculat
5、eduse25. 26. lastUpdatelasttimeframeratewascalculated 27. sampleSize30;lengthmemoryLog&cpuLog 28. graphHeight;29. graphWidth;30. 31. fireParticlesnewArray();allactiveflameparticles 32. fireMCMovieClip();canvasdrawingflames 33. paletteavailablecolors34. anchorshorizontalpointsalongwhichactlikemagnets
6、to35. frame;movieclipsboundingbox 36. 37. constructor.Setupevents,timersandobjects 38. PublicfunctionFlames() 39. addChildAt(fireMC,1);40. Rectangle(2,stage.stageWidth-stage.stageHeight2);41. 42. colWidthMath.floor(frame.width/10);43. for(i103. cpucpuMax104. cpuMaxTF.textcpuTF.text;105. 106. |=0) 10
7、7. cpucpuMin108. cpuMinTF.text109. 110. 111. 1000000;112. memoryLog.push(113. memoryTF.textString(memory.toFixed(1)mb114. memoryMax115. memorymemoryMaxmemory;116. memoryMaxTF.textmemoryTF.text;117. 118. memoryMin119. memorymemoryMin120. memoryMinTF.text121. 122. 123. 124. /rendersonscreen,thatshowst
8、rendsapplicationsconsumption 125. drawGraph(126. graphMC.graphics.clear();127. ypoint,xpoint;128. logSizememoryLog.length;129. 130. 131. memoryLog.shift();132. cpuLog.shift();133. sampleSize;134. 135. widthRatiographMC.widthlogSize;136. 137. graphMC.graphics.lineStyle(3,memoryColor,0.9);138. memoryR
9、angememoryMin;139. 140. ypoint(memoryLogi141. xpoint(isampleSize)142. 143. graphMC.graphics.moveTo(xpoint,-ypoint144. continue;145. 146. graphMC.graphics.lineTo(147. 148. 149. cpuColor,150. jcpuLog.length;j+151. cpuLogj100*152. 153. 154. 155. 156. 157. 158. 159. 160. 161. /renderseachparticleupdatesitvalues 162. drawParticles(163. createParticles(20);164. 165. fireMC.graphics.clear();166. variinfireParticles167. varparticlefireParticlesi;168. 169. if(particle.life0)170. delete(firePar
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1