Multiple Webcams in Actionscript - actionscript-3

My company is looking to play Hollywood Squares for next year's Christmas party, and rather than build an entire 3x3 rig for people to sit in, I proposed that I just create a Flash presentation that broadcast 9 webcams to 9 people sitting safely on the ground.
Can anyone guide me to a tutorial on how to hook this up in AS2 or AS3, preferably AS2 since I'm not as well versed in AS3 as I would like to be.
Thanks in advance

Well, in AS3, this is how it should work in theory, however since I only have one camera connected I cant test this myself. Also, people around the interwebs seem to be having some problems with this. Bear in mind that using this many cameras is likely to grind your application to a halt.
var totalRows:int = 3;
var totalCols:int = 3;
var videoWidth:int = this.stage.stageWidth / totalCols;
var videoHeight:int = this.stage.stageHeight / totalRows;
for (var i:int = 0; i < Math.min(Camera.names.length, totalRows * totalCols); i++) {
var currRow:int = Math.floor(i / totalCols);
var currCol:int = i % totalCols;
var video:Video = new Video(videoWidth, videoHeight);
var cam:Camera = Camera.getCamera(i.toString());
if (cam) {
cam.setMode(videoWidth, videoHeight, 30);
video.attachCamera(cam);
video.x = currCol * videoWidth;
video.y = currRow * videoHeight;
this.addChild(video);
}
}
This answer assumes you want to connect all cameras to one computer. Another way to go about this is to hook each camera up to a separate computer and feed the camera streams to a tenth computer for display.

Related

How to add Movie Clips of different sizes next to each other? AS3

Hello everyone so I am having some trouble with this I have Platforms that I add to the stage which are different sizes in Width. What I am trying to do in my for Loop is add more platforms on the right side of the current platforms x position on stage. I am having trouble because they are different sizes so they end up over lapping each other on this side-scroller game. I align the Platform MC's to the right of the registration like so:
here is the smaller size Movie clip:
I am doing this because I want to add different obstacles to each frame inside the Platform Movie Clip.
add Initial platform:
private function addInitPlatform():void
{
platforms = new mcPlatforms();
platforms.x = (stage.stageWidth / 2) - 380;
platforms.y = (stage.stageHeight / 2) + 175;
addChildAt(platforms, 1);
aPlatformArray.push(platforms);
}
Then add new platforms:
private function addPlatForms():void
{
//Loop trhough Platform Array
for (var i:int = 0; i < aPlatformArray.length; i++)
{
var currentPlat:mcPlatforms = aPlatformArray[i];
nOffSetX += currentPlat.width + 50;
//Add platforms
platforms = new mcPlatforms();
platforms.x = nOffSetX;
platforms.y = (stage.stageHeight / 2) + 175;
addChildAt(platforms, 1);
aPlatformArray.push(platforms);
break;
}
trace(aPlatformArray.length + " NPLATFORMS");
}
I am trying to get the current platform which is the last platform I added to the stage and get its width so i can add it at the end but it still is doing something weird and overlapping over time,
So I was wondering if anyone knows how I should go about solving this so whenever I add on a new platform Movie Clip to the stage it aligns on the right side of the last platform Movie clip added to the stage with some space in between like so:
Thank you in advance!
I'm guessing that you have bunch of different platforms in your library with Linkage names set. Not sure if you want them to be in random order or not, but anyways you probably want to pick them up from an array, so:
var aPlatformsArray:Array = [p1,p2,p3]; //Platform Mc's from library
var addedPlatforms:Array = new Array(); //Array where we store added platforms
The first method was to simply raise offset after adding each platform:
var offsetX:Number = 0; //Starting x for the first platform
for(var i:int=0; i<10; i++){
//Just picking random ones from the Linkage array:
var platform:MovieClip = new aPlatformsArray[Math.floor(Math.random() * aPlatformsArray.length)]();
platform.y = 200;
platform.x = offsetX;
offsetX = platform.x + platform.width + 50;
addChild(platform);
addedPlatforms.push(platform);
}
And actually you don't need to worry about the second method as it's technically slower.
But the main difference is that now we have an array where we pick platforms to the stage, and another array where we push added platforms. The second array is not needed at this point, but you'll probably need it later.
And for offset calculations we use x and width of the "previous" element +fixed gap.
And if you just needed fixed order for the platforms, you'd use similar condition for the loop as you already did, and pick platforms in correct order:
for(var i:int=0; i<aPlatformsArray.length; i++){
var platform:MovieClip = aPlatformsArray[i];
Let me know if this does the job or if I got something wrong.

Trying to generate sword swinging attack using Box2D in Citrus Engine

I've been banging my head up against a wall for the past couple of days trying to figure out how to properly extend CitrusEngine's Box2DPhysicsObjects to generate my custom objects. My goal is to generate this behavior:
example of desired behavior.
This is designed to simulate my hero dashing at a direction determined by using input while swinging his sword to attack. The sword "sleeps" until the attack state is activated.
I think I have a fundamental misunderstanding of how to properly use Box2D (especially joints). If someone could point me in the right direction I would be eternally grateful. I can't really provide my current code because it's become beyond broken.
An implementation such as the one above would have very poor performance and would likely tunnel in almost every situation. Therefore a solution is to add a sensor with a funnel shape and add a joint between this sensor and my hero. The implementation:
override protected function createShape():void{
var radius:Number = 4;
var vertices:Vector.<b2Vec2> = new Vector.<b2Vec2>();
vertices.push(new b2Vec2(0,0));
for (var i:int = 0; i < 7; i++) {
var angle:Number = i / 6.0 * .5* Math.PI;
vertices.push(
new b2Vec2( radius * Math.cos(angle),
radius * Math.sin(angle) ));
}
var sword_shape:b2PolygonShape = new b2PolygonShape();
sword_shape.SetAsVector(vertices,8);
_shape = sword_shape;
}

Camera.setMode sets small resolution

I have a Lenovo tablet with Windows 8.1 with front and rear cameras.
The rear camera is IMX175 and should supports 3280*2464 pixels.
When I call setMode with those dimensions I never got them back (in Camera.width/height) but some lower numbers.
In IE (11) I get 1280*960
In Chrome I get 1920*1440
I tried to change the frame rate to several options, set the stage.quality to StageQuality.BEST.
Any help will be appreciated
There are several reasons between the cam-specifications, flash-player and browsers which affect the final maximal resolution. I dont think, you'll able to attach the full (foto)resolution of the IMX175 to a video-object...
In the past I wrote this script to detect the real possible resolutions of webcams in flash.
function testCams():void
{
var camNames:Array = Camera.names;
for (var i:int; i< camNames.length; i++)
{
var camName:String = camNames[i];
trace(camName,"\n================================");
var cam:Camera = Camera.getCamera(i.toString());
cam.setMode(8000,6000,1);
var camMaxWidth:Number = cam.width;
var camMaxHeight:Number = cam.width;
trace("Maxima w,h: ",camMaxWidth,camMaxHeight);
//4:3
cam.setMode(camMaxWidth,camMaxWidth/4*3, 100);
trace("Maximum 4:3 w,h: ",cam.width,cam.height);
//16:9
cam.setMode(camMaxWidth,camMaxWidth/16*9, 100);
trace("Maximum 16:9 w,h: ",cam.width,cam.height);
trace("Maximum fps: ",cam.fps);
}
}
testCams();
Test your cams and look what mode is possible. Greetings.

How to display player lives in game AS3

Hey everyone so having a little trouble trying to accomplish this. I understand how to add lives and display them through a Dynamic Text Field on the stage. My game is set up right now to where this happens and whenever the player dies a live decrements so it works fine.
But I want to display and Image of all 3 lives a custom Movie Clip that I drew in Flash CS6 to represent the lives. So All 3 lives will be displayed in the game and once the player dies one of the lives images is removed.
I have some idea on what to do. For instance I created a "for loop" to display all 3 images on the screen and created variables to place them horizontally next to each other with a space of 30 pixels.
But I'm not sure if this is the correct way to approach this. Also kind of confused on how I would remove one of the images when the player dies?
Her is my code so far:
public var playerLives:mcPlayerLives;
private var nLives:Number = 3;
private var startPoint:Point;
private var aPlayerLivesArray:Array;
In my main class Engine:
aPlayerLivesArray = new Array;
addPlayerLivesToStage();
Then the addplayerlivestostage function:
public function addPlayerLivesToStage():void
{
var startPoint:Point = new Point((stage.stageWidth / 2) - 300, (stage.stageHeight / 2) - 200);
var xSpacing:Number = 30;
for (var i = 0; i < nLives; i++)
{
trace(aPlayerLivesArray.length);
playerLives = new mcPlayerLives();
stage.addChild(playerLives);
playerLives.x = startPoint.x + (xSpacing * i);
playerLives.y = startPoint.y;
aPlayerLivesArray.push(playerLives);
}
}
So like i stated above everything works fine and it does display the 3 images that represent the lives, but would this be the correct approach or is there an easier method?
i think you're using right way to add lives.
and for removing them, you don't need to remove all and add new lives, you can remove the last element of lives array, so, it's done, i think thats already an easy method
so, you can implement this
for (var i = 0; i < nLives; i++)
to make a better usage for "adding lives in-game (earning lives)"
something like
for (var i = aPlayerLivesArray.length; i < nLives; i++)
but don't forget to decrease array length by 1 after removing last element of livesArray when player dies
Looks pretty close to a reasonable approach. I would have a blank container movieclip on stage where you want the lives icons to display. Create one life icon in your library and link it for export with actionscript. When you generate your game view, you can populate this container with the starting value of three lives. Place the first one, then place the subsequent ones based on the first location.
Some untested code:
NOTE: The following presumes your container clip for the lives is named lives_container and your link instance name for the life icon in the library is Life_icon.
var numberOfLives:Number = 3;
var iconSpacing:Number = 5;
var nextX:Number = 0;
for(var i:int = 0; i < numberOfLives; i++ )
{
var icon:MovieClip = new Life_icon();
icon.x = nextX;
lives_container.addChild( icon );
nextX += icon.width + iconSpacing;
}
This way you could add extra lives easily if the player gained any by adding new icons at the last nextX value, like so:
function addLife():void
{
var icon:MovieClip = new Life_icon();
icon.x = nextX;
lives_container.addChild( icon );
nextX += icon.width + iconSpacing;
}
or remove them as the player loses them:
function removeLife():void
{
var numberOfLivesDisplayed:Number = lives_container.numChildren();
lives_container.removeChildAt( numberOfLivesDisplayed - 1 );
nextX -= icon.width + iconSpacing;
}
Using a container clip for the lives icons makes adjusting the location of the life icons easier if it becomes necessary later.

AS3 enemy formations

I have been developing a shooter game in as3 using the starling framework by looking at some different tutorials.
The problem is that all tutorials teach to create random enemies that move from one side to other. I want to know how can I create different formations of enemies on screen.
Can anyone suggest any books, tutorials, or any basic algorithm to put me on track?
Here is a rather simple way to spawn a formation.
Create a symbol in your library called formation and use that as your linkage/class name as well.
In that symbol place 5 marker MovieClips at whatever locations you want. For the marker clip I recommend using a circle that is centered. Wherever you place those markers, represents where the enemies will be spawned.
Now, in your code where you want to spawn this formation, you can do this :
var formationData:MovieClip = new formation;
for (var index:int = 0;index < formationData.numChildren;index++)
{
var spawnMarker:MovieClip = formationData.getChildAt(index) as MovieClip;
var enemy:Enemy = new Enemy;
enemy.x = spawnMarker.x;
enemy.y = spawnMarker.y;
addChild(enemy);
}
Now, that will spawn a formation based on what you set up in your formation symbol.
You can offset the location of your enemies that get spawned by doing something like this :
var offsetX:Number = 200;
var offsetY:Number = 50;
for (var index:int = 0;index < formationData.numChildren;index++)
{
var spawnMarker:MovieClip = formationData.getChildAt(index) as MovieClip;
var enemy:Enemy = new Enemy;
enemy.x = offsetX + spawnMarker.x;
enemy.y = offsetY + spawnMarker.y;
addChild(enemy);
}
What this concept allows you to do, is visually layout your formations in the flash IDE. So you could create a whole bunch of different formations and choose a random one. Have the spawn points spell out a word ?
Obviously the code above is an example, you would need to integrate the concept into your spawn system etc.
Depending on where your enemies are spawning from, you might need to use the offset to start them offscreen.