00:00
00:00

As: Non Virtual Cameras

6,252 Views | 11 Replies
New Topic Respond to this Topic

As: Non Virtual Cameras 2005-07-03 03:29:01


AS: Main
I used alot from Macromedia LiveDocs

I will try and cover the camera object here, this allows you to intercept data from the user's webcam and could be a very sweet gimmick for your game ;)

So How Does it Work?

Flash has a built it "Camera" Object, we need to learn to manipulate it.

Locating the camera:

First of all we must attach the camera to an object so we can process it :

var cam:Camera= Camera.get();

note that Camera.get(); is what's needed rahter then a constructor (with new) since there is no data we need to create, the camera is already attached.

Camera.get() returns null if there is no camera available or the camera is undefined.

Now that we have defined the camera, it's time to

Set it's mode:

This is done by the setMode command, it sets the width, the height and the FPS your camera will capture (when possible)

setMode(width:Number, height:Number, fps:Number);

let's say I want my camera to capture 300*300 and have 12 fps, you can not exceed the max FPS of the users camera, so better be safe then sorry

can.setMode(300,300,12);

you can always find the current fps with cam.currentFps, and the fps it SHOULD capture in as can.fps.

now we should

set the quality of the picture

cam.setQuality(bandwidth:Number, frameQuality:Number)

we should never use too much bandwidth since it might trouble the user's computer,
examples:

// Ensure that no more than 8192 (8K/second) is used to send video
cam.setQuality(8192,0);

// Ensure that no more than 8192 (8K/second) is used to send video
// with a minimum quality of 50
cam.setQuality(8192,50);

// Ensure a minimum quality of 50, no matter how much bandwidth it takes
cam.setQuality(0,50);

Set the sensativity

the next thing we need to do is set the motion level needed for the onActivity trigger (which we will use when the camera moves)
syntax:
cam.setMotionLevel(sensitivity:Number, timeout:Number )

timeout is used to determine when the activity has ended, to trigger the onActivity(false) handler. it is in miliseconds

cam.setMotionLevel(30, 500);

this is a fair example, 500 is .5 seconds,

And if the user denies?

if the user denies you access from his/her camera, you have to know to trigger stuff accordingly, I suggest you use Camera.onStatus

here is an example (From livedocs)

my_cam.onStatus = function(infoObj:Object) {
switch (infoObj.code) {
case 'Camera.Muted' :
trace("Camera access is denied");
break;
case 'Camera.Unmuted' :
trace("Camera access granted");
break;
}
};

you can keep prompting the user by using System.showSettings(2) remmember, if the user clicks "remmember setting" and he pressed "no" you're done.

Actually Capturing Video, the Video object

frist of all let's declare a Video object
var myVid:Video;

now we must attach our 'cam' object to the Video to make it valid:
myVid.attachVideo(cam);

now the video and the camera are integrated. the myVid object is actually also a movieclip since it extends it, now all you have to do is give it width and height and walla, you integrated your camera ;)

now you can:

1)add a userpic to your game
2)create video chat with XMLSockets (still very hard :P)
3)create an actual action based game

Hope I helped, ask any questions

Response to As: Non Virtual Cameras 2005-07-07 15:09:30


Nice one,quite helpful.


BBS Signature

Response to As: Non Virtual Cameras 2005-08-02 08:43:20


so how would you use a microphone

Response to As: Non Virtual Cameras 2005-08-02 08:49:12


if that didn't help you go to the games of gondor forum (link in the main webpage) there is a tutorial about this in the flash forum.

Response to As: Non Virtual Cameras 2005-08-02 08:52:47


Hmm cool :D

I might try to make a pop the bubbles game sometime.


the events are merely fictional, written, directed, and acted out by all who create them

BBS Signature

Response to As: Non Virtual Cameras 2005-10-30 06:40:30


Nice, there's lot's of posabilitys you could have now, this helped me Thanks :D


Murad136, heres your fucking credit ;3

BBS Signature

Response to As: Non Virtual Cameras 2006-08-06 10:23:24


i put this:
new Camera();
var cam:Camera= Camera.get();
cam.setMode(300,300,12);
cam.setQuality(8192,0);
cam.setQuality(8192,50);
cam.setQuality(0,50);
cam.setMotionLevel(30, 500);

cam.onStatus = function(infoObj:Object) {
switch (infoObj.code) {
case 'Camera.Muted' :
trace("Camera access is denied");
break;
case 'Camera.Unmuted' :
trace("Camera access granted");
break;
}
};
var myVid:Video;
myVid.attachVideo(cam);

In the first frame. It's not working. I have obviously done something wrong. Also I know this is bumping an old topic but it's asking about the tutorial so this is the best place for it.


f

BBS Signature

Response to As: Non Virtual Cameras 2006-08-06 10:28:53


That's pretty cool. The problem is that not everyone already has a web cam, making games made with this kind of useless.


Come join music competitions on Chips Compo and hang on our Discord!

Good artists copy. Great artists get banned from the Audio Portal.

BBS Signature

Response to As: Non Virtual Cameras 2006-08-06 10:42:51


At 8/6/06 10:28 AM, johnfn wrote: That's pretty cool. The problem is that not everyone already has a web cam, making games made with this kind of useless.

It's still good for the people that do have webcams. Just like flash is good for people that do have flash player.


f

BBS Signature

Response to As: Non Virtual Cameras 2007-01-05 16:34:14


Well , it didn't worked neither here!
I think i'm doing something rong... altough there are no errors in the action script...

But it would be cool if you could make a flash game where the player needs to have a webcam to play it then you could record and save it on your computer how the player is playing in the game!!!! mwuahahahahaha that would be very cool! Imaging that Tom Fulp was testing out the game it was some dumb ass game where you needed to imitate something!!
and its recorded and saved on your computer!! you could send it out to the whole internet!!

OK.. I'm over reacting now..


The music made me do it!

BBS Signature

Response to As: Non Virtual Cameras 2007-02-01 17:29:28


So how would you use this to detect WHERE the movement is, in order to make a webcam game?

Or have I completely missed the point :p

...

BBS Signature

Response to As: Non Virtual Cameras 2007-02-01 17:33:00


At 2/1/07 05:29 PM, edit-undo wrote: So how would you use this to detect WHERE the movement is, in order to make a webcam game?
Or have I completely missed the point :p

the simplest method for static cameras, is to add together the difference of each channel for each pixel between current and previous picture, and then if its above a threshold, motion has occured.

to find WHERE the movement is, you can simply apply the same thing to samples of the image, lets say 20x20 samples, obviously smaller samples, more precise measurement


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature