Advertisement
Rolpege

FlashPunk resizable tilemap

Jul 18th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public function resize(width:int, height:int):void
  2.         {
  3.             if (usePositions)
  4.             {
  5.                 width /= _tile.width;
  6.                 height /= _tile.height;
  7.             }
  8.            
  9.             _temp = _map.clone();
  10.             _map = new BitmapData(width, height, false, 0);
  11.             _map.copyPixels(_temp, _map.rect, FP.zero);
  12.             _temp = new BitmapData(width, height, false, 0);
  13.             resizeCanvas(width * _tile.width, height * _tile.height);
  14.             updateAll();
  15.            
  16.             _columns = width;
  17.             _rows = height;
  18.         }
  19.  
  20. //Then on canvas you modify:
  21.  
  22.         public function Canvas(width:uint, height:uint)
  23.         {
  24.             resizeCanvas(width, height);
  25.         }
  26.        
  27.         public function resizeCanvas(width:uint, height:uint):void
  28.         {
  29.             _width = width;
  30.             _height = height;
  31.             _refWidth = Math.ceil(width / _maxWidth);
  32.             _refHeight = Math.ceil(height / _maxHeight);
  33.             _ref = new BitmapData(_refWidth, _refHeight, false, 0);
  34.             var x:uint, y:uint, w:uint, h:uint, i:uint,
  35.             ww:uint = _width % _maxWidth,
  36.                 hh:uint = _height % _maxHeight;
  37.             if (!ww) ww = _maxWidth;
  38.             if (!hh) hh = _maxHeight;
  39.             while (y < _refHeight)
  40.             {
  41.                 h = y < _refHeight - 1 ? _maxHeight : hh;
  42.                 while (x < _refWidth)
  43.                 {
  44.                     w = x < _refWidth - 1 ? _maxWidth : ww;
  45.                     _ref.setPixel(x, y, i);
  46.                     _buffers[i] = new BitmapData(w, h, true, 0);
  47.                     i ++; x ++;
  48.                 }
  49.                 x = 0; y ++;
  50.             }
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement