We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Deep Sea Fish (Actionscript) -- HELP!
Page Index Toggle Pages: 1
Deep Sea Fish (Actionscript) -- HELP! (Read 612 times)
Deep Sea Fish (Actionscript) -- HELP!
Feb 11th, 2008, 12:37am
 
Hello all,

I was told this is where I should come for help! I am learning how I can make fish randomly flow from the left side of the screen to the right.

I have figured out the basics... But now I am stuck!

The ActionScript so far is as follows:

var scale:Number = 45;
var numSegs:Number = 35;
var segLength:Number = 7;
var xthing:Number = 100;
var ything:Number;
var foo:Number = 0;
var bar:Number = 42;



//var clipList:Array;

//clipList = ["head1", "head2", "head3", "head4"]

//clipList[random(clipList.length)]);

// this section creates the head

var seg:MovieClip = attachMovie("head", "seg"+0, 201);

seg._xscale = seg._yscale = scale;

// creates the body
for (var i = 1; i<numSegs-1; i+=2) {

var seg:MovieClip = attachMovie("segment", "seg"+i, 200-i);

seg._xscale = seg._yscale = scale;

var seg:MovieClip = attachMovie("segment2", "seg"+(i+1), 200-(i-1));

seg._xscale = seg._yscale = scale;

}

// adds the tail

var seg:MovieClip = attachMovie("tail", "seg"+numSegs, 200-numSegs);

seg._xscale = seg._yscale = scale;

function onEnterFrame():Void {


// xthing, ything are variables that we will use to move the head

xthing+=10;

foo = foo+.1;

ything=Stage.height/2 + Math.sin(foo)*100;

// this call positions the head relative to xthing, ything

dragCascade(this.seg0, xthing, ything);

// this loop deals with the rest of the creature

for (var i = 0; i<numSegs; i++) {


var segA:MovieClip = this["seg"+i];


var segB:MovieClip = this["seg"+(i+1)];


dragCascade(segB, segA._x, segA._y);


}
}

// dragCascade just rotates a thing to point at some x, y coordinate
function dragCascade(seg:MovieClip, x:Number, y:Number):Void {

var dx:Number = x-seg._x;

var dy:Number = y-seg._y;

var angle:Number = Math.atan2(dy, dx);

seg._rotation = angle*180/Math.PI;

seg._x = x-Math.cos(angle)*segLength;

seg._y = y-Math.sin(angle)*segLength;
}

The Project file can be downloaded here: http://www.megaupload.com/?d=PJKVOXHU  

What I wanted to know was:

1) How can I make the fish reappear again after it has flowed off frame?

2) If possible, how can I make multiple fish flowing from left to right (And also have random flowing motions)?

3) Finally, how would I make the number of fish vary in depth (Make them bigger or smaller on the screen)?

ANY help on this would be much appreciated!

I've VERY new to programming, and I need all the advice I can get.

TIA,
Jack
Re: Deep Sea Fish (Actionscript) -- HELP!
Reply #1 - Feb 11th, 2008, 10:25am
 
I'm sorry, but whoever told you this is the place to come for ActionScript help is wrong, this is the forum for Processing which has nothing to do with ActionScript. There's a chance someone here has done some, but you're much better off asking on a ActionScript specific forum.
Page Index Toggle Pages: 1