Reputation: 221
I have a simple chunk of code in plain as3 that copies pixels from a MC and uses them to be displayed on several objects (something like a live puzzle which parts are across the stage).Yet from what I`ve read and gathered, if I want the performance to be at its max i should use Starling. But! from the post I have found I didnt quite get if the RenderTexture (.draw) is really a better solution.
And as the code is fairly simple (and cause im quite new to Starling) can I ask how it would be this (the code below) translated into Starling.
private var movingPicture:MovieClip = new RollerCoaster();
private var _sourceBitmapData:BitmapData = new BitmapData(500, 500);
private var elements:Array = [];
private function onFrame( ev:Event )
{
_sourceBitmapData.lock();
_sourceBitmapData.draw( movingPicture );
for(var r:int = 0; r < row; r++)
{
for(var c:int = 0; c < col; c++)
{
elements[r][c].bmd.copyPixels(_sourceBitmapData, new Rectangle( (c * elementW ), ( r * elementH ), elementW, elementH), myPoint);
}
}
_sourceBitmapData.unlock();
}
//elements[r][c] is a MovieClip and it has some vars in, that can be used, like :
//public var bmd:BitmapData;
//public var bm:Bitmap;
//PS: I never add **movingPicture** to the stage, I just use it to copy from it
Upvotes: 0
Views: 87
Reputation: 7510
Using Starling you won't be able to manipulate those textures in that easy way. It will cost you a lot of learning in order to do it. Furthermore you have to think of your graphics in a whole new way. The textures are "baked" at the beginning and uploaded to GPU, and after then almost no modifications could be done (in meaning of replacements of the textures). You will need to use shaders and stuff like that.
And depending on your needs, the performance could not be that better. If you need to change the graphics often (which will mean new upload to GPU), it could even be a drawback.
From my experience, the learning curve is pretty tough and so if you just need a few simple manipulations I would advise you to stick to regular AS. You should also know that copying pixels is extremely fast, and won't save you much time if you leave it. And by that time - rendering a new texture (uploading it to the GPU) is extremely slow. For example on a Samsung S3, it would take to upload a regular 800x600 texture between 500 and 800ms in my app.
So there is no "best" way it depends on your needs, your code and your device. Good luck!
Upvotes: 2