Flash notes by Edzis

ActionScript programmer / Flash developer Edgars Simsons on professional stuff

Blur on rotationY = 0? Use transform.matrix

with 14 comments

matrix3D vs matrix in image quality

matrix3D vs matrix in image quality

If you have run across bad quality visuals after doing DisplayObject transformations in 3D (rotationX, rotationY, rotationY or z-axis modifications) you might want to use transform.matrix to get back the quality.

I wanted to make a simple 3D animation in Adobe AIR 1.5 / FlashPlayer10 content in AIR – the DisplayObject should rotate around the Y axis from 90 to 0. The animation worked fine, but as soon I was changing the rotationY the content got blurry, even if i just set the rotationY to 0. I tried different solutions and was about to shout out for help when I remembered reading somewhere that as soon as the third dimension is applied to a Display object its transform.matrix is replaced with transform.matrix3D. And indeed after the animation is done I set DisplayObject.transform.matrix and the blur is gone! Flash removes all the 3D transformations. You might see that the image on right is much crisper, especially on the small horizontal lines.

However, if anybody knows why the content is blurred the first place despite no actual 3D transformation and/or other solutions how to remove it, I would love to hear that!

Written by edzis

November 4th, 2008 at 2:55 pm

Posted in Adobe Air, Flash Player 10

Tagged with , ,

14 Responses to 'Blur on rotationY = 0? Use transform.matrix'

Subscribe to comments with RSS or TrackBack to 'Blur on rotationY = 0? Use transform.matrix'.

  1. When you say “set DisplayObject.transform.matrix”. What code do you use?

    Brian

    25 Nov 08 at 18:53

  2. var myMc:DisplayObject = new Sprite();
    // be it Sprite, MovieClip, Shape or whatever extends DisplayObject
    // add content

    myMc.rotationY = 0;
    // makes the content blurry

    myMc.transform.matrix = new Matrix();
    // removes 3D transformation

    see http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObject.html

    edzis

    25 Nov 08 at 20:59

  3. Hi, i’ve came across the same problem, and your solution works. But it resets the position of the object and when i try to position it again, it becomes blured again. Even if i position it like this -> object.transform.Matrix = new Matrix(….., x, y);

    Any ideas ?

    Thanks

    Pedro Valentim

    19 Jan 09 at 18:55

  4. Apparently any children of a displayObject who has rotationY applied also inherit the the Matrix3D object so the child also need to be reset.

    JR

    23 Jan 09 at 11:36

  5. Thanks, JR, for the note – didn’t think of this.

    edzis

    23 Jan 09 at 11:40

  6. Hey Edzis,

    I came across this problem earlier. I saw what you wrote above but still cant figure about how to apply it to an existing movieclip I have on the stage. I added your code but I dont know how to apply the displayObject to an existing movieclip. Im fairly new to AS3 so any help on this would be greatly appreciated.

    Thanks,

    David

    David

    17 Mar 09 at 22:45

  7. Great fix, i solved the repositioning issue by setting a variable to the x position just before resetting the matrix, and then quickly applying that x position back on right after the reset. Probably lots of better ways of doing this but it seems to work fine.

    Heres some of my code:

    function resetMatrix(curNum:int) {
    var curMc:DisplayObject
    curMc = holder_mc.getChildByName(“child”+curNum);
    var xPos:int = curMc.x
    curMc.transform.matrix = new Matrix();
    curMc.x = xPos;
    }

    Anders

    18 Mar 09 at 19:29

  8. [...] de votre objet. Utilisez le code suivant : monObjet.transform.matrix = new Matrix(); Lien: Flash notes by Edzis. Flash & [...]

  9. I’m having the same blurry problem when rotating Y. But this fix doesn’t really work for me cos the clip has to stay at 180 Y rotation when the tween finishes.

    Any help on this?

    Thanx

    Jimmy

    9 Jun 09 at 09:31

  10. If you want to kill the blur, you have to find a way to go back to the 2D space.
    I imagine you have a Sprite with 2 children – one facing the front and another the back. If so, you could play the flipping animation and once it is done flip the children to the other sides (what was rotationY 180 now becomes 0 and vice versa) and set the container back to rotationY 0 and use set the transform matrix.

    edzis

    9 Jun 09 at 09:48

  11. Hi and thanx for the answer!

    Yes exactly like that : container clip with 2 children: front and back. I’m using TweenLite for the tween and used the gotoandlearn tut code from here: http://www.gotoandlearn.com/play?id=91

    Some of my code:

    function tweenStep1():void{
    TweenLite.to(step1, 1.5, {rotationY:180, x:84, y:100, scaleX:1, scaleY:1, ease:Expo.easeOut, onComplete:tweenStep2});

    addEventListener(Event.ENTER_FRAME, loop1);

    function loop1(e:Event):void{
    if (step1.rotationY>90 && step1.rotationY= 360){
    step1.rotationY = 0;
    }
    }

    }

    Then if I add new matrix in the next func:

    function tweenStep2(){
    step1.transform.matrix = new Matrix(step1.scaleX, 0, 0, step1.scaleY, step1.x, step1.y);
    }

    the container clip step1 goes to rotationY:0

    Any further help pls?

    Jimmy

    9 Jun 09 at 09:57

  12. the solution I suggested makes your step1 go to rotationY 0. But I see no code for the front and back faces.

    function tweenStep2(){
    step1.front_mc.rotationY = 180;
    step1.back_mc.rotationY = 0;
    step1.transform.matrix = new Matrix(step1.scaleX, 0, 0, step1.scaleY, step1.x, step1.y);
    }

    or for better performance you could just make the new back face invisible.

    edzis

    9 Jun 09 at 10:08

  13. Ok thanx so much.

    I made the front mc invisible and rotated the back mc, and it’s close to what I’m looking after. 1 Problem thou: Now when I apply new matrix the step1 mc suddeny jumps and it looks much more uglier than the bure itself :)

    Thanx anyway!

    Jimmy

    9 Jun 09 at 10:21

  14. He he :D This makes me think about what JR wrote:

    “Apparently any children of a displayObject who has rotationY applied also inherit the the Matrix3D object so the child also need to be reset.”

    So maybe you could try to loop trough the children tree of step1 and set the matrix to items in all levels.

    edzis

    9 Jun 09 at 10:28

Leave a Reply