# Caching and rendering my spritesheets doesn't work - help

**URL:** https://forum.kirupa.com/t/caching-and-rendering-my-spritesheets-doesnt-work-help/325610
**Category:** Uncategorized
**Created:** [October 25, 2011, 11:12pm UTC](https://forum.kirupa.com/t/caching-and-rendering-my-spritesheets-doesnt-work-help/325610 "2011-10-25T23:12:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![drpelz](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@drpelz](https://forum.kirupa.com/u/drpelz)
#### Post date: [October 25, 2011, 11:12pm UTC](https://forum.kirupa.com/t/caching-and-rendering-my-spritesheets-doesnt-work-help/325610/1 "2011-10-25T23:12:09Z")

</div>

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

```auto

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

```auto

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();
            
            
        }

```
