I have a game that produces new chunks of terrain as the player explores, to allow for a seemingly unlimited level size. It's been working perfectly, but I decided to let my character travel in one direction for a long time, and eventually it gets this error:
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData/ctor()
at flash.display::BitmapData()
At this line of code:
this.new_chunk.background_bitmap_data = new BitmapData(this.level_obj.block_size * this.new_chunk.blocks_wide + this.level_obj.oversize_bmd_offset,this.level_obj.block_size * this.new_chunk.blocks_tall + this.level_obj.oversize_bmd_offset,true,0x00000000);
I ran a trace();
on the variables/equations that provide the width and height values being used to create the bitmap data, and it outputs the same values constantly, as intended:
2150 1300
I ran my character in a number of different directions, and the same thing eventually happens regardless of direction. I know that the BitmapData
isn't getting too large, because it's always 2150x1300.
Note: The error does not occur while staying in a small area, no matter how long I leave the game running, the error only occurs after traveling in one direction for a long time, generating numerous new chunks of level.
Any ideas why flash is throwing this error?
EDIT:
Here is a live demo of the game so you can get a better understanding of what's going on: http://test.webskethio.com/boxy/
(Controls are W.A.S.D for movement, hold shift to move faster.)
Each "chunk" is the size of the game screen itself, each chunk stores a cached BitmapData
of all of the smaller BitmapData
s that make it up (the tiles of grass, trees, rocks, flowers, etc.) The chunk BitmapData
is loaded to a Bitmap
on the stage when the chunk is close enough to the stage that it can end up needing to be rendered.
EDIT 2:
I've uploaded a picture to illustrate what I believe is Amy's proposed method of rendering for my game that doesn't require the storage of many BitmapData objects:
The four corner colored areas are BitmapData
objects that will be drawn to the one Bitmap
on the screen (same size as the user's screen, represented in green.) The black area around the whole thing represents what at one point could have been other BitmapData
objects which have been set to null
since they are no longer needed.
The 4 corner BitmapData objects will be redrawn to the main Bitmap
with new point coordinates as the player moves.