Be a Supporter!

As: Non Virtual Cameras

  • 5,459 Views
  • 11 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
As: Non Virtual Cameras Jul. 3rd, 2005 @ 03:29 AM Reply

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

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As: Non Virtual Cameras Jul. 7th, 2005 @ 03:09 PM Reply

Nice one,quite helpful.


BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As: Non Virtual Cameras Aug. 2nd, 2005 @ 08:43 AM Reply

so how would you use a microphone

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to As: Non Virtual Cameras Aug. 2nd, 2005 @ 08:49 AM Reply

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.

Starogre
Starogre
  • Member since: May. 8, 2004
  • Offline.
Forum Stats
Member
Level 18
Artist
Response to As: Non Virtual Cameras Aug. 2nd, 2005 @ 08:52 AM Reply

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
3ruce
3ruce
  • Member since: Jul. 23, 2005
  • Offline.
Forum Stats
Member
Level 09
Artist
Response to As: Non Virtual Cameras Oct. 30th, 2005 @ 06:40 AM Reply

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


Murad136, heres your fucking credit ;3

BBS Signature
Spectacle
Spectacle
  • Member since: Apr. 10, 2006
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Non Virtual Cameras Aug. 6th, 2006 @ 10:23 AM Reply

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
johnfn
johnfn
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Non Virtual Cameras Aug. 6th, 2006 @ 10:28 AM Reply

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


[6,11,4,10,2,10,-68,5,15,-68,16,4 ,1,-68,-2,1,15,16,-67].map(function(v){ return String.fromCharCode(v + 100) }).join(""); // updated for web 2.0!

BBS Signature
Spectacle
Spectacle
  • Member since: Apr. 10, 2006
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Non Virtual Cameras Aug. 6th, 2006 @ 10:42 AM Reply

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
Play2jens
Play2jens
  • Member since: Sep. 9, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to As: Non Virtual Cameras Jan. 5th, 2007 @ 04:34 PM Reply

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
edit-undo
edit-undo
  • Member since: Jan. 17, 2006
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to As: Non Virtual Cameras Feb. 1st, 2007 @ 05:29 PM Reply

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
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Non Virtual Cameras Feb. 1st, 2007 @ 05:33 PM Reply

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