开发者

Problems positioning Flash graphic drawn with Graphics Class

I'm using Flash CS3 to build a simple drawing application. When the user clicks a button, they select a particular movieclip. After clicking elsewhere on the stage, the clip is instantiated and added to the stage at the position of the cursor. I've also added the option of being able to click on the added clip and drag it around on the screen. And this all works fine.

The problem is that I also want to be able to dynamically draw and add objects to the stage via the Graphics class. Whenever I add objects in this manner, their x and y coordinates are always 0,0 no matter where I place them on the stage. This makes positioning these graphics very ve开发者_运维技巧ry problematic. I created a modified positioning function specifically for these dynamically drawn graphics and while it does "work", it feels less responsive than the positioning for movieclip objects. I'm still trying to optimize this function, but it seems to me that the ideal solution is for the graphics to have non-zero coordinates when placed in the middle of the stage like movieclip objects. Is there some "workaround" to achieve this?


If you're going to be drawing with the graphics class inside of a movieclip/sprite you'll need to draw it to a bitmap and display the bitmap instead of the movieclip. Movieclips can only hold so much vector information and even if you draw over something the shape that gets created with the Graphics class is still actually there. You'll find that if you track your frame rate with something like Mr Doob's Stats class, as you begin to fill up the MovieClip the fps will plummet. The solution is to use the draw() method of BitmapData and copy what's inside of the movieclip to the bitmap that you're displaying. When you create the bitmap you'll have to link it to the BitmapData. Every time u call draw it'll update the Bitmap for you (which is nice).

I built a painting app last week so I have first hand experience with this issue.


You can change the registration point of the display object using the matrix class .

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html


You have to draw inside a movieclip and then move that movieclip around. The drawings are actually bound to the object itself, so you can't move them around independently. So just make a container, draw on that, and move your container around inside the other clip.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜