SmashCam Class

June 18th, 2008

This Actionscript 3 class is very useful for just about any game you are developing in Flash. I made this “SmashCam” class based off of Colin Moock’s vCam. I was really impressed by what it can do for animators in Flash and it inspired me to use it for developers who make Flash games. The vCam isn’t really complicated a script, it is very straight forward – its a real clever script on how to use a movie clip as a camera. Let me show you what the script does in action, move the blue circle with arrow keys around the stage.

The SmashCam is actually set right now to focus and maintain the square and circle in the center of the stage as the two movie clips move around and about. But in this example only the blue circle is moving. The green painted clouds on the stage are there to help you see that blue circle is moving and the stage is enlarging and shrinking to the affect coming from the SmashCam.

I won’t go into too much detail on how to setup the .fla to have the circle move around stage, since that tutorial is in my last post, but I will show how to set up the SmashCam. This is what is you need to do:

[as]
// SmashCam(display_container:MovieClip, target1:MovieClip, target2:MovieClip, [width:int = 600, [height:int = 450]]);
var camera:SmashCam = new SmashCam(this, Circle, Square);
[/as]

Thats it. The SmashCam takes three required parameters, the display_container,target1,target2, and two optional parameters width and height (the default width is 600, and default height is 450). You can also set up the SmashCam’s minimum and maximum width and height of how far it should scale the display_container like so:

[as]
camera = new SmashCam(this, Circle, Square, 550, 400);
camera.min_width = 200;
camera.min_height = 150;
camera.max_width = 2000;
camera.max_height = 1500;
[/as]

All that is left to explain is the calculation of the SmashCam executed every frame. To do so, in the main game loop add this line of code:

[as]
camera.calculate();
[/as]

I will let you do the rest of the experimenting and looking into of what the SmashCam Class is really doing. I appreciate any feedback on improvements or better alternatives. Or if you have questions, I will do my best to explain. Thanks and have fun!

SmashCam class download

AS3

One Response to “SmashCam Class”

  1. as3isolib Says:

    I think this would be a great asset to have for the as3isolib, somehow incorporating the concepts into a modified IsoView. Great work!

Leave a Reply

Enter code snippets inside of <pre> and </pre>