I’m working with another developer on an app. His part is basically a control panel, developed as a standalone module, and has to be integrated in my main app.
My app has to redraw all the panels and elements in a bitmapData to do some bitmapData.hitTest control (we’re working on a multitouch table, panels are draggable but overlapping has to be avoided).
Until yesterday I was working with a placeholder, that means I was basically drawing a simple shape of the exact dimension of the module he’s working on. Today we tried for the first time to merge all together and the performance are very different. It looks like that the process of redrawing his module instead of my placeholder shape is causing a big perfomance drop.
Is it normal? I thought that the process of drawing a display object inside a bitmapData in terms of performance was related to the dimension of the clip, not to its content.
EDIT: I already fix it with a workaround (basically drawing something like the bounding box of the panel object), but I’m still curious about it 🙂
The performance will be in part dictated by the contents of the display object. Depending on the number and complexity of the children being drawn this can vary significantly. Take for example that you could potentially draw 10,000 (arbitrarily large number) of sprites that are 1px by 1px (arbitrarily small number) all stacked on top of one another. Each sprite could contain in it’s drawing code tons of arbitrary vector commands (moveTo, lineTo etc.) to draw, even outside of the visible area, these drawing commands will be executed regardless of the drawing area when the drawing methods are invoked (unless specific code stops them from being called for particular constraints). I don’t believe you should see a significant difference in drawing the display objects to a BitmapData object versus drawing them to the screen though (the only difference I can think of here is writing to RAM/heap space whereas with GPU acceleration it might internally be using the video RAM instead).
I believe the hitTest itself wouldn’t be affected by the number of children since at that point you are just looking at pixels in A vs pixels in B, so it should as you say, only depend on the area of pixels in A and B.
Out of curiosity what kind of touch surface are you using and what’s the platform it’s working on (Android?). I’d imagine with a good processor like a Tegra 2 or 3 (or some other multi-core and/or GPU accelerated chip-set) this wouldn’t create such a performance impact that it would be noticeable (though I could be wrong). I’ve been working a bit on a top down shooter game and recently switched from using a simplified hit test method I wrote using the bounding boxes to using BitmapData’s hit test method, testing it locally it doesn’t seem to affect performance negatively, but I don’t have a cable with me to test it on device yet so I’m not sure if it’s going to cause a performance impact when run on the device.