actionscript 3 - AS3 : Scaling Sprite with Matrix on slider change? -


i have sprite holds bitmap data. want give user ability resize image slider. using code beneath, can see problem scaling additive image gone totally.

i understand have scale in non additive way, can not figure out how?

i tried pass :

var m:matrix = userimagecopy.transform.matrix; 

when userimagecopy holds original image. helped scaling then, each time scaling started userimage jumped position of userimagecopy.

any help?

function onsliderchange(evt:event):void     {         trace( evt.target.value);         //this create point object @ center of display object          var ptrotationpoint:point = new point(userimage.x + userimage.width / 2,userimage.y + userimage.height / 2);         //call function , pass in object rotated, amount scale x , y (sx, sy), , point object created         scalefromcenter(userimage, evt.target.value, evt.target.value, ptrotationpoint);     }      private function scalefromcenter(ob:*, sx:number, sy:number, ptscalepoint:point)     {         var m:matrix = userimage.transform.matrix;         m.tx -=  ptscalepoint.x;         m.ty -=  ptscalepoint.y;         m.scale(sx, sy);         m.tx += ptscalepoint.x;         m.ty += ptscalepoint.y;         ob.transform.matrix = m;     } 

rather combining center values current tx , ty, set them directly matrix.translate method:

private function scalefromcenter(ob:*, sx:number, sy:number, ptscalepoint:point) {     var m:matrix = new matrix();     m.translate(-ptscalepoint.x,-ptscalepoint.y);     m.scale(sx, sy);     m.translate(ptscalepoint.x,ptscalepoint.y);     ob.transform.matrix = m; } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -