February 09, 2012, 07:54:15 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: Flash vCams here  (Read 5566 times)
0 Members and 1 Guest are viewing this topic.
chluaid
Bitey's Daddy
Administrator
Heroic
*****
Offline Offline

Gender: Male
Posts: 5374


ldf l srff r drlt sdtr


WWW
« on: September 28, 2008, 04:51:26 PM »

For AS 2.0
Code: (reanimator.camera)
import flash.geom.Matrix;
import flash.geom.Transform;
import flash.geom.ColorTransform;
var cameraTrans:Transform = new Transform(this);
var stageTrans:Transform = new Transform(this._parent);
var w:Number = Stage.width;
var h:Number = Stage.height;
this._visible = false;
this.onEnterFrame = function () {
this._parent.filters = this.filters;
stageTrans.colorTransform = cameraTrans.colorTransform;
var stageMatrix:Matrix = cameraTrans.matrix;
stageMatrix.invert();
stageMatrix.translate(w*.5, h*.5);
stageTrans.matrix = stageMatrix;
};


For AS 3.0
Code: (Jaehl's AS3 cam, supports filters)
var cameraTrans:Transform = new Transform(this);
var stageTrans:Transform = new Transform(parent);
visible = false;

stage.addEventListener(Event.ENTER_FRAME, updateStage);
function updateStage(...rest) {
parent.filters = filters;
stageTrans.colorTransform = cameraTrans.colorTransform;
var stageMatrix:Matrix = cameraTrans.matrix;
stageMatrix.invert();
stageMatrix.translate(stage.stageWidth*.5, stage.stageHeight*.5);
stageTrans.matrix = stageMatrix;
};
updateStage();

addEventListener(Event.REMOVED_FROM_STAGE, resetStage);
function resetStage(...rest) {
stage.removeEventListener(Event.ENTER_FRAME, updateStage);
stageTrans.matrix = new Matrix();
stageTrans.colorTransform = new ColorTransform();
parent.filters = new Array();
}


To use these, simply create a movieclip symbol making sure that its Registration point is in the centre (as below):



Inside the symbol, create your vCam artwork (usually an empty square with the same dimensions as your movie) and put the above code on the same frame. Whenever you want to use the camera, simply drag it out of your Flash library onto the Stage. Tweening this camera symbol on the Stage creates camera moves, easy as that Smiley

vCam 1.0 was created by Sham Bhangal in 2004 for "Prowlies at the River"
reanimator.camera by Jarrad Hope was the first vCam to allow filters and rotation.
Jaehl's AS3 cam was created by request for us here, because he's so awesome.

As has always been the case, Actionscript programmers are encouraged to tweak and make their own enhancements/improvements to the vCam.
Animators and programmers, wherever you use the vCam or improve on it, always show respect by giving credit to the people who created it or contributed to the code.
« Last Edit: November 21, 2010, 10:04:12 PM by chluaid » Logged

<a href="http://bitey.com/images/dashkin/728_animated1.swf" target="_blank">http://bitey.com/images/dashkin/728_animated1.swf</a>
Vector
Resident Actionscript Guru
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 3803


~ Programmer | National Laser Tag Player | Bent ~


WWW
« Reply #1 on: June 14, 2009, 05:42:59 PM »

DISCLAIMER: don't take my word for any of this, as I haven't had the time to learn AS3 in the last year an a half, and haven't had flash installed on my computer for about 9 months, but...

From a quick glance, it would appear that both the AS2 and AS3 cameras above do not clean up after themselves properly. It may not be a problem for the AS2 cam due to the way it keeps its-self operating, however the AS3 cam may leave your screen transformed even after you delete the camera from the stage.

What this means for you is if you want to stop using the camera by deleting it from the stage, you'll need to do a little workaround. After the last frame that you use your camera, add one more. On that frame, have the camera centred, and matching the stage's original width and height. After that frame you can delete the camera.
Logged

~Vector
chluaid
Bitey's Daddy
Administrator
Heroic
*****
Offline Offline

Gender: Male
Posts: 5374


ldf l srff r drlt sdtr


WWW
« Reply #2 on: June 14, 2009, 11:32:33 PM »

yeah that's how I've been doing it but there's a way to do this in AS. Anthony Eden gave me the fix for Waterlollies but I seem to have misplaced the cam from that movie. It removes any stage transform when the cam clip is removed from the stage. I'm waiting for him to get back to me (which is why I PMd you about it) so when he does, I'll update the code above.
Logged

<a href="http://bitey.com/images/dashkin/728_animated1.swf" target="_blank">http://bitey.com/images/dashkin/728_animated1.swf</a>
adzy-2k6
Senior Member
****
Offline Offline

Posts: 717


« Reply #3 on: June 15, 2009, 03:45:30 AM »

Couldnt you copy the cam from the waterlollies source file, or have you deleted it?. Odds are, that is the quickest way we will get it back Smiley
Logged

chluaid
Bitey's Daddy
Administrator
Heroic
*****
Offline Offline

Gender: Male
Posts: 5374


ldf l srff r drlt sdtr


WWW
« Reply #4 on: June 16, 2009, 01:31:02 PM »

Couldnt you copy the cam from the waterlollies source file, or have you deleted it?. Odds are, that is the quickest way we will get it back Smiley

I could but it's on my old computer which doesn't have a monitor, keyboard or mouse, since I'm using them all on my brand new machine. Probably easier to ask Jaehl or Snepo point out the problem and edit the post Grin
Logged

<a href="http://bitey.com/images/dashkin/728_animated1.swf" target="_blank">http://bitey.com/images/dashkin/728_animated1.swf</a>
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #5 on: June 16, 2009, 06:28:16 PM »

Ta-da!  Grin

Code:
import flash.geom.Matrix;
import flash.geom.Transform;
import flash.geom.ColorTransform;
var cameraTrans:Transform = new Transform(this);
var stageTrans:Transform = new Transform(this.parent);
var w:Number = stage.stageWidth;
var h:Number = stage.stageHeight;

stage.addEventListener(Event.ENTER_FRAME, updateStage);
function updateStage(...rest) {
//this._parent.filters = this.filters;
stageTrans.colorTransform = cameraTrans.colorTransform;
var stageMatrix:Matrix = cameraTrans.matrix;
stageMatrix.invert();
stageMatrix.translate(w*.5, h*.5);
stageTrans.matrix = stageMatrix;
};
updateStage();

this.addEventListener(Event.REMOVED_FROM_STAGE, resetStage);
function resetStage(...rest) {
stage.removeEventListener( Event.ENTER_FRAME, updateStage);
stageTrans.matrix = new Matrix();
}
« Last Edit: October 29, 2009, 11:05:55 PM by Jaehl » Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
chluaid
Bitey's Daddy
Administrator
Heroic
*****
Offline Offline

Gender: Male
Posts: 5374


ldf l srff r drlt sdtr


WWW
« Reply #6 on: June 16, 2009, 11:08:58 PM »

I hope you're earning a lot of money somewhere man Smiley
Logged

<a href="http://bitey.com/images/dashkin/728_animated1.swf" target="_blank">http://bitey.com/images/dashkin/728_animated1.swf</a>
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #7 on: June 17, 2009, 12:47:27 AM »

gah! Oh God, don't even mention money, I'm so ridiculously poor right now! Tongue
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
TheEYE
Lurys Fey Daemyt
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 5750


That which you have seen can never be unseen.


« Reply #8 on: June 17, 2009, 09:53:20 AM »

That's AS3 correct Jaehl?
If you weren't already a MotM, you would be for this alone my friend, good on ya bud!  Grin
Logged

Ambition is the last refuge of failure. -Arthur Wilde
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #9 on: June 17, 2009, 11:31:29 AM »

No problem Cheesy

And yeah, it's AS3. Here's the AS2 version:
Code:
import flash.geom.Matrix;
import flash.geom.Transform;
import flash.geom.ColorTransform;
var cameraTrans:Transform = new Transform(this);
var stageTrans:Transform = new Transform(this._parent);
var w:Number = Stage.width;
var h:Number = Stage.height;
this._visible = false;
this.onEnterFrame = function() {
this._parent.filters = this.filters;
stageTrans.colorTransform = cameraTrans.colorTransform;
var stageMatrix:Matrix = cameraTrans.matrix;
stageMatrix.invert();
stageMatrix.translate(w*.5, h*.5);
stageTrans.matrix = stageMatrix;
}

this.onUnload = function() {
stageTrans.matrix = new Matrix();
}
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Jeemanx
Woodfolk
*
Offline Offline

Posts: 35



« Reply #10 on: June 17, 2009, 10:26:29 PM »

I thought I'd ask here whether there are any tutorials on how to implement these cameras in flash (CS4)?

I've followed Adam's directions in this thread but can't get anything working. I've also downloaded the older example from the links page with Adam's 'waterfall' scene, but the code seems totally different to the examples shown here.

'pologies for the n00bness - but I'd never even thought of having a camera to move around in flash before today.. Smiley

[EDIT] It's OK - I got it to work. I didn't have the correct publish settings in my scene.. D'oh!
« Last Edit: June 17, 2009, 11:55:44 PM by Jeemanx » Logged

"What's so bad about being drunk?"
"Ask a glass of water."
Darkswift2204
Junior Member
**
Offline Offline

Posts: 98


« Reply #11 on: June 24, 2009, 07:57:49 AM »

Hey i need help i do what adams says but i cant get it to work. Do i have to make a square and make the square a symbol or what?
Logged

Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #12 on: June 24, 2009, 09:09:30 AM »

Make a rectangle that's exactly the same size as the movie itself, turn it into a movieclip, open it up, and stick the code on the first frame. Smiley
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1417


/* No comment */


WWW
« Reply #13 on: October 29, 2009, 11:05:37 PM »

Update: The vCam now supports filters!
Code: (AS3)
var cameraTrans:Transform = new Transform(this);
var stageTrans:Transform = new Transform(parent);
visible = false;

stage.addEventListener(Event.ENTER_FRAME, updateStage);
function updateStage(...rest) {
parent.filters = filters;
stageTrans.colorTransform = cameraTrans.colorTransform;
var stageMatrix:Matrix = cameraTrans.matrix;
stageMatrix.invert();
stageMatrix.translate(stage.stageWidth*.5, stage.stageHeight*.5);
stageTrans.matrix = stageMatrix;
};
updateStage();

addEventListener(Event.REMOVED_FROM_STAGE, resetStage);
function resetStage(...rest) {
stage.removeEventListener(Event.ENTER_FRAME, updateStage);
stageTrans.matrix = new Matrix();
stageTrans.colorTransform = new ColorTransform();
parent.filters = new Array();
}
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.15 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.069 seconds with 25 queries.