PDA

View Full Version : Zoom in/out



zerosum
September 17th, 2008, 12:50 PM
Hi there,

I have a quick question - how do you create a zoom in/out effect in Flash, much like the one in this game: http://nonoba.com/yaief/race-to-the-bottom

I want the "camera" to follow the two objects each player control, and get closer and farther as they move ... and I have no clue how to do it.

As usual, thanks a bunch!

spooks222
September 22nd, 2008, 09:12 AM
i'm curious about this as well, how do you keep the movieclip, centered at all times?

bluemagica
September 22nd, 2008, 09:30 AM
are you using as2 or as3? in any case, put all the stuff inside a movieclip and scale that clip to get the zoom effect, alternatively, look into Vcam on google!

spooks222
September 22nd, 2008, 10:48 AM
using actionscript 3. scale the clip to get the zoom effect? so i would make the stage long, and just allow the movieclip to scroll across it?

bluemagica
September 22nd, 2008, 01:02 PM
What do you mean? Zerosum asked about a racing game, which already has scrolling! And since you can only see the portion of the clip that is on stage.....scaling the clip will create the zoom effect.

SparK_BR
September 22nd, 2008, 05:18 PM
it's like creating a subStage
then you have Stage, a subStage clip, that will act like your stage
and the zoom will be the subStage size(subStage must be a perfect square)

when making the camera effect, change a var and then apply the var value for both _width and _height

you said you have 2 players, then
sqrt(player2 position^2) - sqrt(player1 position^2)
(distance betwen them) divided by 2 will be the center of the screen, this distance multiplied by 2 will be the subStage size

you will need a max zoom, in case both players stay in same position then the camera won't be showing 1 large pixel in screen

:2c:

zerosum
January 31st, 2009, 10:13 AM
Argh, so long time no seen, sorry for this.
I wonder if anyone is still listening to this thread - anyway, if so, how would that subStage thing work? I am always at a loss when it comes to those weird flash quirks ...

Anyhow, thanks a bunch!

therobot
January 31st, 2009, 12:08 PM
Argh, so long time no seen, sorry for this.
I wonder if anyone is still listening to this thread - anyway, if so, how would that subStage thing work? I am always at a loss when it comes to those weird flash quirks ...

Anyhow, thanks a bunch!

OK, just think about what happens when you zoom in - things appear to get bigger right? well, you make things bigger in flash two ways - either by adjusting its x scale & y scale, or by adjusting its width and height.

The easiest way to do this is by adjusting x scale and y scale.



// how to do this in as2
// in as2, a 'fresh', untouched movieclip will have a scale of 100.
// to make something half the size as normal
someMovieClip._xscale = someMovieClip._yscale = 50;


// how to do this in as3
// in as3, scale is represented as a percent,
// meaning 1 is normal, .5 would be half the size, etc.
someMovieClip.scaleX = someMovieClip.scaleY = .5;


So that is how you can resize things right? You could make zooming in and out hard or easy on yourself. The easiest way to do this is to put all the things you want to zoom inside of a movieclip, then control the x and y scale of that 'container' movieclip, because it will dynamically resize not only the container movieclip, but everything inside of it as well. The hard way to do this would be to zoom every item separately, one by one, which would be a tremendous pain, so you should get used to grouping similar objects into movieclips.

zerosum
January 31st, 2009, 08:03 PM
hi the robot! thanks for the answer!

just to be sure, what you mean by putting it in a container is to make a sprite/movie clip, and then all the elements their children? Something like:

subStage.addChild(carOne)

and then just modify the scale using that subStage:

subStage.scaleX = subStage.scaleY = 0.5

thanks!

Jephz
February 2nd, 2009, 10:28 AM
*cough*...vcam*cough cough*

therobot
February 4th, 2009, 01:02 AM
hi the robot! thanks for the answer!

just to be sure, what you mean by putting it in a container is to make a sprite/movie clip, and then all the elements their children? Something like:

subStage.addChild(carOne)

and then just modify the scale using that subStage:

subStage.scaleX = subStage.scaleY = 0.5

thanks!

exactly. put all your stuff in a movieclip that you intend to treat as a container. anything you do to that container clip will directly affect anything in the container. move the container, you'll move everything inside of it all at once, fade it, rotate it, scale it, etc. apply a mask to the container and you'll also end up masking all of its contents.

So now, if you want to zoom in on, try putting a tween on your container clip that will tween the scale over time, or adjust the scale onEnterFrame



function onEnterFrame( evt:Event ):void
{
myContainerClip.scaleX += 0.01; // increase the scale by 1% every frame
myContainerClip.scaleY = myContainerClip.scaleX;// make sure you scale the y too :)
myContainerClip.x += 1; // move the thing 1 pixel to the right every frame
}



*cough*...vcam*cough cough*

I'd steer clear of something like vcam if you're still trying to get the basics down :)