A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [C++][Alchemy][F10]Faster ways to clear a bitmap?

  1. #1

    [C++][Alchemy][F10]Faster ways to clear a bitmap?

    Not sure where to put this question as it relates to Alchemy...

    I'm making a game which does all the rendering in C++, and passes as an address in memory to be created as a BitmapData from a Byte Array in Flash.

    What I'm working on now is creating my own semi BitmapData class in C++. I'm working on a similar fillRect method like the one in the AS3 BitmapData class.

    I want to know if there is a fast way of setting every single pixel to a certain color instead of going through every single pixel and setting the color in a while loop. Maybe some sort of trick perhaps?

    I did tests with a 500 by 500 Bitmap, and using C++, in Flash 10, using my loop method, is quicker than the AS3 alternative, but I still want to know if there's a better way.

    Basically, is there a better way to clear an array of pixels in a Bitmap to one color without having to loop through each pixel?

    Anyone know how AS3 runs their fillRect method behind the scenes?


  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Lost forever in a happy crowd...
    An idea I've had rattling around in my head for a while is to use triple buffering and pixel blender to clear the screen, eg

    Screen A: The one currently being displayed
    Screen B: Being plotted to
    Screen C: Being wiped ready to move up to being screen B next frame.

    I mean this is assuming that you're just using one bitmap canvas to blit to, and that pixel blender running in it's own thread is actually quicker than either as3 or c running via Alchemy ( That's the bit I don't know ).

    Dunno if that's any help as an alternative for you mate, it could be a total non-starter, but it feels good.

    It'd be interesting to hear more about what you're doing with Alchemy, there seems to be so much potential to it, it'd be great to hear from someone actually using it for something "real".


  3. #3
    I see how triple buffering would be quicker this way, but I don't know if multi-threading is allowed in Flash using C++ via Alchemy. Never tried it though. Will keep an open mind about Triple Buffering. Sounds interesting, thanks for the idea Squize.

    The project is a space shooter which uses BOIDS.

    I basically started it a long time ago, but was annoyed at having to compromise organization for speed. For example, not using getters and setters. Plus I love the control C++ gives me, such as direct access to memory and pointers, and Type arrays.

    About clearing the bitmap to one color. Anyone know how the pros do it? Do they loop through a single large int array changing every int?


  4. #4
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Not exactly what you are looking for, but:


    Can only set it per byte, not sure how to set a larger chunk then a byte repeating.

    Note the comparison times against a for loop.

  5. #5
    Thanks Unknownguy.
    This could actually work. Especially if I want to clear my array to 0.
    Even if I use char(byte) I can still set every byte to 0, thereby clearing all my pixels to a 100% transparent black.
    Will definitely work for a clear to transparent black, which is mainly what I use.

    Will do my own tests with this function.

    Wonder what that function actually does though. Accesses some even low level commands than C?

    Just did a test and the memset is actually drastically slowing down my program. And it's setting a pretty large chunk of memory. A 250000 long int array. According to the doc testing, the larger the array, the more speed gained when using memset, instead of a for loop. But I'm getting really slow results.

    Last edited by tariqm; 01-04-2009 at 09:58 PM.

  6. #6
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Maybe it is because of what flash player does with it(something unexpected)? Though I do not really know.

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