A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: [problem] zoom and focus

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    [problem] zoom and focus

    [great new thread starter]
    we really need to have a sticky per game genre. in a clean thread. that would be awesome

    anyway, [problem]

    i need to zoom in a MC, while focusing a known object... let's say yyyMC inside the xxxMC (xxxMC is located at 0;0)

    the zoom code i wrote:
    code:

    // load
    proportion = this.xxxMC._height/this.xxxMC._width;
    zoom_value = 100;
    // loop
    this.onEnterFrame = function() {
    this.xxxMC._width++;
    this.xxxMC._height = this.xxxMC._width*proportion;
    zoom_value--;
    if (zoom_value==0) {
    delete this.onEnterFrame;
    }
    };



    ^ here, the image will be zooming during 100 frames...

    now my question is: how to focus on this.xxxMC.yyyMC? so that it's located in the middle of the window when the zoom is finished?

    say i catch its _x/_y values on load
    code:

    px = this.xxxMC.yyyMC._x
    py = this.xxxMC.yyyMC._y



    but what's next...? sure, it's simple, but... where is my logic!?!

    thanks for the answers...

  2. #2
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    I thought I knew how to do this untill I actaully tried.

    What I'm thinking is this... calculate the distance from the centre of the yyyMC to the point where you want it to go ( for example the centre of the Stage ). Do this in seperate components, like you've started to do, px and py. This has to take into account all the _parents positions, and relative stuff - might be easier to use localToGlobal() ?? Once you've found them, divide them by zoom_value, and that will give you small distances in x- and y-direction. Add this small amount each frame, and it *should* now be centred.

    I've had a quick play around with this, but for some strage reason, it's stopping just ever so slightly off-centre. I can only think i've left something out, but i can't see what

    I think the theory should still work though. You could get much fancyer ones that "ease" to the centre, whereas the above moves there at a constant rate, like your magnification.
    jonmack
    flash racer blog - advanced arcade racer development blog

  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    I've had a quick play around with this, but for some strage reason, it's stopping just ever so slightly off-centre. I can only think i've left something out, but i can't see what
    hehe, same for me, i started to try some methods/ways, but each time the MC was not correctly put...
    it's so logical that it flies upon my head, probably

    also, for some reason i would like to avoid the localToGlobal()... have you ever wanted to create a cd-rom portofolio with a main animation loading one of your game.swf working with localToGlobal()? you ended up with a lot of values to change, unless you already knew that the game was intended to be loaded in another movie in the future...

  4. #4
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Ahha! Just had an idea. I was forgetting to take into account that the thing was also zooming, and I think that is why it's not quite aligning properly.

    I see what you mean about localToGlobal. A shame. But you do still need to know the relative positions of things. How are you supposed to make it go to a certain point, if you don't know where that point is from you!? Just as long as you have everything in one container mc ( xxxMC? ) then it should be possible.

    BTW, i haven't figured out how to modify it yet Just one idea on where the problem lies, in case you can figure it out too... Will keep trying.
    jonmack
    flash racer blog - advanced arcade racer development blog

  5. #5
    flash junk extravagante
    Join Date
    Oct 2003
    Location
    netherlands
    Posts
    105
    Am I just being plain stupid here, or could this be resolved by placing the MC's registration point at centre and maybe increasing _xscale and _yscale instead of _height and _width ?

    I'm quite sure I'm just being plain stupid
    signatures after the show, thank you.

  6. #6
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    nothing is supposed to be centered...

    xxxMC._x=0
    xxxMC._y=0

    ^ that's the MC containing a lot of another MCs, including yyyMC

    let's say in xxxMC i have:

    yyyMC._x=200
    yyyMC._y=350

    your method works only if both xxxMC AND yyyMC are centered...

    i'm still trying, drawing squares on a paper and zooming it manually, maybe i will be inspired... i wish i hadn't lost a lot of my maths knowledges.

  7. #7
    Junior Member
    Join Date
    Dec 2003
    Posts
    28
    i wrote this function a while back, maybe im just tired but i dont completely get what you are asking! anyway, a bit of 'code for thought' is never a bad thing! basically centres an attached movieclip nomatter the registration point...


    code:
    MovieClip.prototype.centre = function() {
    with(this) {
    var b = getBounds(_root);
    cenX = (b.xMin + (_width/2));
    cenY = (b.yMin + (_height/2));
    }
    var p = {x:cenX, y:cenY}; this.localToGlobal( p);
    var xPos = (Stage.width/2) - p.x;
    var yPos = (Stage.height/2) - p.y;
    var point = {x:xPos, y:yPos};
    return point;
    }



    [m]

  8. #8
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Originally posted by marmotte
    i'm still trying, drawing squares on a paper and zooming it manually, maybe i will be inspired...
    Hehheh, right there with ya buddy. And a page of vector stuff came up with something horridly complicated... that still didnt'work when i tried it. Meh.. too tired to code anymore, that's me done for the day.

    nice code je.. i mean mbenney. But it has the horrible localToGlobal! ^^ Pull off one of your miracles and solve this so i can get some sleep, eh?
    jonmack
    flash racer blog - advanced arcade racer development blog

  9. #9
    I'm feeling supersonic kdsh7's Avatar
    Join Date
    Jul 2002
    Posts
    356
    I don't think it's possible without localToGlobal - maybe someone will prove me wrong, but things like this are exactly what the commands were meant for! Don't be scared of those commands, they're really powerful and in my opinion, essential.

    Nice code mbenney, as always!

    Marmotte, hopefully someone will come up with a solution - localtoglobals all over the place can get very confusing, but sometimes they're the only way to make things work.

  10. #10
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks for your time jonmack... i'm still having no success, and ended with codes complicated like xxxMC._x += (aa*10)/((bb+cc)*(dd/ee)), these kinds of things.


    thanks jesus... i don't know, but for now each time someone talks about jesus, i have matrix in mind...

    maybe a better explanation?

    > i have an image... // ex: jesus walking
    > i want to zoom in... // code above, working
    > i want the zoom to focus on jesus's head // now his face fills the entire screen

    that's it

    Don't be scared of those commands, they're really powerful and in my opinion, essential.
    not afraid, i'm a big boy now
    as i said, most of my old games used them... yes, tehy are useful, but i mentionned the cd-rom portofolio example, where they may cause some probs...
    anyway, i can try to use them also...
    Last edited by marmotte; 12-01-2003 at 07:51 PM.

  11. #11
    I'm feeling supersonic kdsh7's Avatar
    Join Date
    Jul 2002
    Posts
    356
    ah - if it was me I'd cheat and use a tweened animation :P

  12. #12
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Originally posted by kdsh7
    ah - if it was me I'd cheat and use a tweened animation :P
    i see what you mean, i'm generaly a cheater too
    but no chance to use tweened animation, since the MC i want to focus is rarely at the same place...

  13. #13
    Might have misunderstood you, but if you want to avoid using local to global, you can get the same effect by adding the MC's x coor with all its parent MC's x coors.

    Hopefully I misunderstood you or else it might look bad for you & Jon =p

    ~yarr

  14. #14
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Originally posted by jtnw
    Might have misunderstood you, but if you want to avoid using local to global, you can get the same effect by adding the MC's x coor with all its parent MC's x coors.

    Hopefully I misunderstood you or else it might look bad for you & Jon =p

    ~yarr
    Meh... can't sleep.

    Yeah, that's what i tried first. But because the MC's are then expanding, the relative values change. And that's what I forgot to think about. I thought they should all change by the same amount, by the "expansion factor", but I tried that too and it still didn't work. But I'm guessing it's just a silly mistake on my part, and i've missed something out

    Anybody got any good "cures" for insomnia - other than easy looking maths problems that turn out to ellude you
    jonmack
    flash racer blog - advanced arcade racer development blog

  15. #15
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Anybody got any good "cures" for insomnia
    ^_^
    for me it's 4:18 in the morning actually. already.

  16. #16
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  17. #17
    Ihoss
    Guest
    i ws working on a manual localToGlobal because i hated the flash version. its something like this, although im in school so im not sure:
    code:

    function localGlobal(mc,dmc){
    lx=(_root[dmc]._x*_root[mc]._xScale)+_root[mc]._x;
    lx=(_root[dmc]._x*_root[mc]._xScale)+_root[mc]._x;
    _root.lx=lx
    _root.ly=ly;
    }


    mc is the mc on the stage. dmc is an mc inside mc.

  18. #18
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks a lot blink, that's exactly what i was looking for... i just tried your .swf, it's perfect.
    i need to adapt it a little bit now, i hope it can be done with your code (since my zoom is a progressive one, and focus on a MC instead of the mouse position, but it shouldn't be a problem )...

    also, thanks for your custom localToGlobal ihoss

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