A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: changing movieclip size

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    changing movieclip size

    i want to make it so when the movieclip moves (arrow keys) closer to the top it gets smaller and moves slower, and when it gets to the bottom it gets bigger and moves faster.

    Here is a working code I have, but I need to think of something better.


    Actionscript Code:
    if (this._y < 700){
        this._xscale = 120;
        this._yscale = 120;
        _level0.speed = 3.6;
    }
    if (this._y < 650){
        this._xscale = 115;
        this._yscale = 115;
        _level0.speed = 3.4;
    }
    if (this._y < 600){
        this._xscale = 110;
        this._yscale = 110;
        _level0.speed = 3.2;
    }
    if (this._y < 550){
        this._xscale = 105;
        this._yscale = 105
        _level0.speed = 2.8;
    }
    if (this._y < 500){
        this._xscale = 100;
        this._yscale = 100;
        _level0.speed = 2.6;
    }
    if (this._y < 450){
        this._xscale = 95;
        this._yscale = 95;
            _level0.speed = 2.4;
    }
    if (this._y < 400){
        this._xscale = 90;
        this._yscale = 90;
            _level0.speed = 2.2;
    }
    if (this._y < 350){
        this._xscale = 85;
        this._yscale = 85;
            _level0.speed = 2;
    }
    if (this._y < 300){
        this._xscale = 80;
        this._yscale = 80;
        _level0.speed = 1.8;
    }
    if (this._y < 250){
        this._xscale = 75;
        this._yscale = 75;
        _level0.speed = 1.6;
    }
    if (this._y < 200){
        this._xscale = 70;
        this._yscale = 70;
        _level0.speed = 1.4;
    }
    if (this._y < 150){
        this._xscale =65;
        this._yscale = 65;
        _level0.speed = 1.2;
    }
    if (this._y < 100){
        this._xscale =60;
        this._yscale = 60;
        _level0.speed = 1;
    }

    the only problem with this is that it is by 50's. I figure I would need a formula

    Can any one point me into a direction?

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I guess I dont understand exactly what it is your after doing?

    do you want it to continually 'size' itself depending on the direction and on each movement?

    or only after a certain amount of movement in either direction?

    maybe something like this (not tested)

    actionscript Code:
    var distance:Number = 1;
    var speed:Number = .1;

    var scale:Number = 1;
    var scaleIncrease:Number = .1;

    var keyListener_obj:Object = new Object();
    keyListener_obj.onKeyDown = function() {
        switch (Key.getCode()) {
            case Key.UP :
            if(targetClip_mc._y >= (0 + targetClip_mc._width/2)){
                trace("TARGET Y: "+(0 + targetClip_mc._width/2));
                trace("CURRENT Y: "+targetClip_mc._y);
                targetClip_mc._y -= distance;
                targetClip_mc._xscale = targetClip_mc._yscale -= scale;
                distance = (distance - speed);
                scale = (scale - scaleIncrease);
                trace("DISTANCE: "+distance);
                break;
            }                                                  
            case Key.DOWN :
            if(targetClip_mc._y <= (Stage.height - targetClip_mc._width/2)){
                trace("TARGET Y: "+(Stage.height - targetClip_mc._width/2));
                trace("CURRENT Y: "+targetClip_mc._y);
                targetClip_mc._y += distance;
                targetClip_mc._xscale = targetClip_mc._yscale += scale;
                distance = (distance + speed);
                scale = (scale + scaleIncrease);
                trace("DISTANCE: "+distance);
                break;
            }
        }
    };
    Key.addListener(keyListener_obj);

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    well i was thing,

    widthandheight = Movieclip._y / stage._y *100
    player._xscale - widthandheight;
    player._yscale - widthandheight;
    and every time the movie clip moves on the _y it will change the codewidth.

    so this way when you move up it looks like you are moving away not up.
    I don't have time to test it, im on the road for business and i didn't bring my laptop. But when i get home i'll check out your code.

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