Tuesday, June 9, 2009

graphics.lineBitmapStyle()

Hello all, here is my random AS3 statement / question of the day. I have posted this on numerous forums, however no one seems to feel like replying, so I figured I would put it on the blog and see what answers I can catch here.

I am trying to mimic a paint brush in AS3 (in flex) for a mock art studio. Right now I am simply checking for mouse down + mouse move then putting a copy of some bitmapData on a sprite, then adding that to the main application. This sucks because after a while it starts to get bogged down.

As a result I checked out graphics.lineBitmapStyle() (an AS3 Flash 10 Feature documentation can be found here), I was able to get that to work (technically) but not how I wanted to use it. Right now it just tiles it (yes, I know there is a switch to turn repeating off) thus causing it to act like a 'scratch off' lottery ticket. What I mean by this is that it looks like there is a static image underneath (this is my bitmap) and my 'drawing' on the stage just makes it visible. Any help would be greatly appreciated... code is below:
Code:

var oldWay:Canvas = new Canvas()
//get bmpdata
var bRect:BitmapData = new BitmapData(100, 100); //create bitmap
var c:Canvas = new Canvas(); //create spoof canvas
c.graphics.beginFill(oxFF0000); //start fill
c.graphics.drawRoundRect(0,0, 100, 100,10,10); //draw that stuff!
c.graphics.endFill(); //end fill
bRect.draw(c); //draw this out to the bmpdata
//now draw it on the stage
oldWay.graphics.lineStyle(bRect.height,0); //start a line style
oldWay.graphics.lineBitmapStyle(bRect,null,true,false) //set bitmap style
oldWay.graphics.moveTo(nX1, nY1); //move the point to my previous point
oldWay.graphics.lineTo(nX2, nY2); //draw to new location

Image of results here:

and with repeating on:

1 comment:

GTD - Danado said...

We're building the same project...
I don't know how far did you get on yours, but it seems that we stucked in the same place: Drawing with brushes!
Ive been looking for lineBitmapStyle usage exambles, hoping that some idea light up my brain.
take a look at www.sergiomoura.com/JellyPaint/

I'll let you know if i get something helpfull.