Reputation: 21
I'm using functional Actionscript 3 and are doing a game where the user leaves tracks on the level.
But now the tracks are objects in an array, that will grow larger and larger (and slow down the game over time). How can I paint them on the level bitmap? And how to reload the bitmap when you restart?
Have searched for an answer for days but have not found one.
I know how to combine a bitmap and add it to the stage, but not how to replace it in the movie clip object:
var newLevel:BitmapData = new BitmapData(grassLevel.width, grassLevel.height);
var newDebree:BitmapData = new BitmapData(debree.width, debree.height);
newLevel.draw(grassLevel);
var position: Matrix = new Matrix(1,0,0,1, user.x, user.y);
newLevel.draw(debree, position);
var bm:Bitmap = new Bitmap(newLevel);
addChildAt(bm, 21);
Upvotes: 1
Views: 440
Reputation:
You're going to want to look heavily into Blitting to do what you want to do. You can have one copy of the tracks in memory, and blit them to multiple locations. Since you're using bitmaps exclusively anyway, I'd wager that this is the best plan.
There's a good tutorial on Blitting here.
Note that you shouldn't have to add a new Bitmap to the stage every time you want to update the image; it should actually update automatically.
Upvotes: 3