Hi all, I’m working on a personal project. Basically, it’s a simple drawing application. So far so good, except for some performance issues when testing on AIR mobile(iOS). I’m on the 3.2 SDK, CPU mode. I’m testing on an iPad 2.
So, in my code I have a function that starts drawing when you do a mouse down and on mouse move. The part that’s bogging it down is an between function… this “walks” the brush between the two points as each mouse move is registered. It’s fine if I go slow/average and with a small brush… but if I use a bigger brush, and go fast… it will slow down. When I say brush, it’s a .png inside of a movie clip that moves around and is drawn on my bitmapData/Bitmap canvas. On desktop, it’s flawless… and working just like I want. Mobile is almost there, and I’m looking for some help on trying to optimize this code.
this.addEventListener(MouseEvent.MOUSE_MOVE, renderPainting)
public function renderPainting(e:Event)
{
if(paintingActive)
{
colorTransform = new ColorTransform()
colorTransform.color = paintColor;
fillInBrush() //This is my magic function.
curBrush.x = this.mouseX
curBrush.y = this.mouseY //curBrush refers to a brush movie clip inside of the "brushHolder" movie clip. I am drawing the bitmapData from this MC as shown below.
paintBitmapData.draw(brushHolder,null,colorTransform,brushBlendMode)
}
}
private function fillInBrush()
{
moveX = this.mouseX - lastX
moveY = this.mouseY - lastY
lineDistance = Math.sqrt( (moveX * moveX) + (moveY* moveY)) / spacing
//spacing is a number set to 4 for this example... that's the pixel amount the brush moves each step.
divX = moveX / lineDistance
divY = moveY / lineDistance
for(var i:uint = 1; i < lineDistance;i++)
{
curBrush.x = lastX + (divX * i)
curBrush.y = lastY + (divY * i)
paintBitmapData.draw(brushHolder,null,colorTransform,brushBlendMode,null,false)
}
lastX = this.mouseX
lastY = this.mouseY
}
Where I’m experiencing the slowdown is in the for loop, on paintBitmapData.draw. Also, the blend mode is simply set to none, and “erase” when I am using the eraser tool. Any input or ideas would be helpful! Thank you - Ben