A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Making a Zoom function. Need math help

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    Making a Zoom function. Need math help

    Hello all,

    I have created a function that zooms (x1.2 or 20%) in and centers the location clicked of a certain movie clip. The second part of this function was to reposition another much smaller movieclip that is on top of that movie clip so that it scales and moves like the whole thing was scaling and moving together. I got most of it figured out and if I take off the zoom tweens I can get this smaller movieclip to go where it is supposed to. The problem is that when the background main movieclip expands 20%, my desired x and y position of the above smaller movieclip moves towards the bottom right corner ever so slightly because it is growing. So basically I need to create an equation that compensates for how much the width and height move throw off the answer that I have so far.

    If the width and height of the background movie clip are growing by 20% then each little part will get bigger 20% bigger but I can't figure this out now because my brain is mush.

    right now I have it like so:

    *f1Valye3x and y are a different variables that correctly find the location of where the correct answer would be if not for the slight growth of the background MovieClip throwing off my values. I am hoping that I can add something that will compensate for that slight growth no matter where it is.

    f1.x = f1Value3X + _________ ;
    f1.y = f1Value3Y + ________ ;

    I am probably doing this backwards by doing it without the zoom first, I dunno.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    here's some more info:

    //finds the point clicked
    _clickPoint = new Point(e.stageX, e.stageY);

    //takes the point clicked and moves it to the top left hand corner as the registration point is in the center of the movieclip(so it'll rotate from the middle)
    var f1SubtractionX = _clickPoint.x + (f1.width/2);
    var f1SubtractionY = _clickPoint.y + (f1.height/2);

    //finds the center of the stage.Plus same movie clip thingy above
    var f1AdditionX = ((stage.stageWidth/2) + (f1.width/2));
    var f1AdditionY = ((stage.stageHeight/2) + (f1.height/2));

    // finds the difference between the two points and adds it to the x and y value of the movieclip on top
    var f1Value3X = ((f1.x) + (f1AdditionX - f1SubtractionX));
    var f1Value3Y = ((f1.y) + (f1AdditionY - f1SubtractionY));

    //hoepfully sets my final x and y values but I need to add the difference the background movieclip makes when it expands by 20%
    f1.x = f1Value3X + _________ ;
    f1.y = f1Value3Y+___________;

    my bigger Movieclip is called BackGroundMap and f1 is the smaller one that is on top. I also have a variable call _zoomSize which is = 1.2.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center