1、mapIndexY1 = uint(y1/256);源码:1. 2. package com.heptaFmon.game.map.layers3. 4. import com.heptaFmon.config.Config;5. import com.heptaFmon.core.BaseDisplayObject;6. import com.heptaFmon.game.map.impl.GameMap;7. import com.heptaFmon.hack.HeptaFishGC;8. import com.heptaFmon.loader.impl.ImageLoader;9. im
2、port com.heptaFmon.map.impl.HashMap;10. 11. import flash.display.Bitmap;12. import flash.events.Event;13. import flash.events.IOErrorEvent;14. import flash.events.ProgressEvent;15. import flash.geom.Point;16. /地图层 图片17. public class MapLayer extends BaseDisplayObject18. 19. /图片读取器20. private var _im
3、ageLoader:ImageLoader;21. /地图图片 用于整块加载模式22. private var _image:Bitmap;23. /地图图片数组 用于栅格式加载地图模式24. private var _imageMap:HashMap;25. /小地图图片26. private var _simage:27. /28. private var _map:GameMap;29. private var _loadType:int;/加载类型 0:整块加载 1:栅格加载30. private var _visualWidth:/地图可视宽度31. private var _vis
4、ualHeight:/地图可视高度32. private var _sliceWidth:/地图切割单元宽度33. private var _sliceHeight:/地图切割单元高度34. private var _preloadX:/横向预加载屏数35. private var _preloadY:/纵向预加载屏数36. private var _loadingMap:/正在加载的屏map37. private var _waitLoadingArr:Array;/等待加载的loadermap38. 39. private var _loadingNo:int = Config.getIn
5、t(concurrencyImageLoader);40. 41. private var _screenImageRow:/一屏需要加载的横向图片数42. private var _screenImageCol:/一屏需要加载的纵向图片数43. private var _row:/总横向节点数44. private var _col:/总纵向节点数45. 46. private var _nowPlayerPointoint;/当前人物所处的屏47. 48. public function MapLayer(map:GameMap)49. 50. _map = map;51. _loadTy
6、pe = parseInt(_map.mapXML.loadType);52. 53. /读取地图图片54. public function load():void55. /加载小地图56. var imageLoader:ImageLoader = new ImageLoader();57. var fileName:String =Config.getValue(mapLib) + _map.name + /map_s.jpg;58. imageLoader.load(fileName);59. imageLoader.addEventListener(Event.COMPLETE,loa
7、dSmallSuccess);60. imageLoader.addEventListener(ProgressEvent.PROGRESS,loadingHandler);61. imageLoader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);62. 63. 64. /读取大地图成功65. private function loadBigSuccess(evet:Event):66. ImageLoader = ImageLoader(evet.target);67. var image:Bitmap = new Bitm
8、ap(imageLoader._data);68. addChild(image);69. if(_simage != null & _simage.parent = this)70. removeChild(_simage);71. _simage = null;72. 73. this.width = image.width;74. this.height = image.height;75. imageLoader.removeEventListener(Event.COMPLETE,loadBigSuccess);76. imageLoader.removeEventListener(
9、ProgressEvent.PROGRESS,loadingHandler);77. imageLoader.removeEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);78. imageLoader = null;79. dispatchEvent(evet);80. HeptaFishGC.gc();81. 82. /读取小地图成功83. private function loadSmallSuccess(evet:84. 85. 86. image.width = _map.mapWidth;87. image.height = _
10、map.mapHeight;88. 89. 90. 91. imageLoader.removeEventListener(Event.COMPLETE,loadSmallSuccess);92. 93. 94. 95. 96. 97. switch(_loadType)98. case 0:/整块加载99. /加载大地图100. var bfileName:/map.jpg101. var bLoader:102. bLoader.load(bfileName);103. bLoader.addEventListener(Event.COMPLETE,loadBigSuccess);104.
11、 bLoader.addEventListener(ProgressEvent.PROGRESS,loadingHandler);105. bLoader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);106. break;107. case 1:108. _loadingMap = new HashMap();109. _imageMap = new HashMap();110. _waitLoadingArr = new Array();111. _visualWidth = _map.app.screen.size.x;11
12、2. _visualHeight = _map.app.screen.size.y;113. _sliceWidth = parseFloat(_map.mapXML.sliceWidth);114. _sliceHeight = parseFloat(_map.mapXML.sliceHeight);115. _preloadX = parseFloat(_map.mapXML.preloadX);116. _preloadY = parseFloat(_map.mapXML.preloadY);117. _screenImageRow = Math.round(_visualWidth/_
13、sliceWidth);118. _screenImageCol = Math.round(_visualHeight/_sliceHeight);119. _row = Math.ceil(_map.mapWidth/_sliceWidth);120. _col = Math.ceil(_map.mapHeight/_sliceHeight);121. loadSliceImage(_map.initPlayerPoint);122. 123. default:124. 125. 126. 127. 128. 129. /根据player坐标读取周边指定屏数地图130. private fu
14、nction loadSliceImage(playerPointoint):131. var nowX:int = Math.floor(playerPoint.x/_sliceWidth);/现在所处的索引X132. var nowY:int = Math.floor(playerPoint.y/_sliceHeight);/现在所处的索引Y133. var nowScreenX:int = Math.floor(nowX/_screenImageRow);/现在所处的屏索引X134. var nowScreenY:int = Math.floor(nowY/_screenImageCol
15、);/现在所处的屏索引Y135. /trace(nowScreenX: + nowScreenX);136. /nowScreenY: + nowScreenY);137. _nowPlayerPoint = new Point(nowScreenX,nowScreenY);138. loadScreenImage(nowScreenX,nowScreenY);139. /removeScreenImage(nowScreenX,nowScreenY);140. var startX:int = (nowScreenX - _preloadX 0 ? 0 : nowScreenX - _pre
16、loadX);141. var startY:int = (nowScreenY - _preloadY _row ? _row : nowScreenX + _preloadX);144. var endY:int = (nowScreenY + _preloadY _col ? _col : nowScreenY + _preloadY);145. 146. for(var xx:int = startX; xx endX;xx+)147. for(var yy:int = startY; yy endY;yy+)148. if(xx = nowScreenX & yy = nowScre
17、enY)149. continue;150. else151. loadScreenImage(xx,yy);152. 153. 154. 155. 156. /加载指定屏的地图图片157. private function loadScreenImage(screenX:int,screenY:int):158. var starX:int = _screenImageRow*screenX _screenImageRow*screenX;159. var starY:int = _screenImageCol*screenY _row - 1 ? _row -1 : _screenImag
18、eRow*(screenX+1);161. int = _screenImageCol*(screenY+1) _col-1? _col-1 : _screenImageCol*(screenY+1);162. for(var yy:int=starY;yyendY+1;163. for(var xx:int = starX;xx 0)176. for(var i:int = 0;i_loadingNo - _loadingMap.size();i+)177. var key:String = _waitLoadingArr.pop();178. 179. String = Config.ge
19、tValue() + _map.name +/ + key+ .jpg180. /fileName: + fileName);181. _loadingMap.put(imageLoader,key);182. imageLoader.addEventListener(Event.COMPLETE,loadScreenImageSuccess);183. 184. 185. 186. 187. 188. 189. 190. /成功加载某屏的图片191. private function loadScreenImageSuccess(evet:192. 193. var tempStr:Stri
20、ng = String(_loadingMap.getValue(imageLoader);194. var tempStrArr:Array = tempStr.split(195. var yy:int = tempStrArr0;196. var xx:int = tempStrArr1;197. _loadingMap.remove(imageLoader);198. 199. image.x = _sliceWidth*xx;200. image.y = _sliceHeight*yy;201. this.addChild(image);202. _imageMap.put(yy+xx,image);203. imageLoader.removeEventListener(Event.COMPLETE,loadScreenImageSuccess);204. imageLoader.removeEventListener(ProgressEvent.PROGRESS,loadingH
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1