A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: caching and rendering spritesheets doesn't work - help

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    85

    Unhappy caching and rendering spritesheets doesn't work - help

    Hello folks,

    I'd like to cache my spritesheet (tilesheet) into an array. I do this because every spritesheet shall be cached inside of an array so my objects can pull their tiles from them easily. But my cache doesn't seem to work because absolutely nothing gets rendered out of it. I can't see anything.

    There is something inside my cache (likely bitmapData) and it is not null so currently I don't know where the problem might be.

    Can someone help me out with this issue, please?


    this function 'separates' my spritesheet into tiles and throws them into an array
    Code:
    private function tileToCache():void {
    			var tileBitmapData:BitmapData = new BitmapData(tileWidth, tileHeight, true, 0x00000000);
    			var tilePt:Point = new Point(0, 0);
    			var tileRect:Rectangle = new Rectangle;
    			
    			
    			tileCache = [];
    			
    			for (var tileCtr:int = 0; tileCtr < tilesLength; tileCtr++) {
    				
    				tileBitmapData.lock();
    				tileRect.x = int((tileCtr % spritesPerRow)) * tileWidth;
    				tileRect.y = int((tileCtr / spritesPerRow)) * tileHeight;
    				
    				tileBitmapData.copyPixels(tileSheet, tileRect, tilePt);
    				tileBitmapData.unlock();
    
    				tileCache.push(tileBitmapData);
    				
    			}
    }
    this function shall render each tile of an array to a background via copypixels
    Code:
    public function renderCachedTile(canvasBitmapData:BitmapData, tileArray:Array):void
    		{
    			
    			tileCache = tileArray;
    			
    			tileArray = [];
    			
    			x = nextX;
    			y = nextY;
    			
    			point.x = x;
    			point.y = y;
    			
    			tileRect.x = tileWidth;
    			tileRect.y = tileHeight;
    			
    			if (animationCount >= animationDelay)
    			{
    				animationCount = 0;
    				
    				if(reverse)
    				{
    					currentTile--;
    					if (currentTile < 1)
    					{
    						currentTile = tilesLength - 1;
    					}
    					
    					
    				} else {
    					
    					currentTile++;
    					if (currentTile >= tilesLength - 1)
    					{
    						currentTile = 0;
    					}
    					
    					
    				}
    				
    			} else {
    				animationCount++;
    			}
    				
    			canvasBitmapData.lock();	
    			
    			
    			canvasBitmapData.copyPixels(tileCache[currentTile], tileRect, point);
    			canvasBitmapData.unlock();
    			
    			
    		}
    Last edited by drpelz; 10-25-2011 at 07:37 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center