-
random to a fixed ponit
hi,
i have a scripting question.
i have 8 different movie clips, random floating around as my flash file loads.
as the files loads, i want the randomly floating movie clips to line up to a certain x and y position, smoothly transitioning from a random point to a given position.
for example, at 12% load, i want movie clip A to move from it's randomly selected location to a specific location on screen.
and as the load progresses, the other 7 in sequence begin to line up.
i'm having the most difficult time doing this.
any thoughts?
thanks!!
go
-
Senior Member
Let's say R is the percentage loaded - most preloaders compute this at some point.
Let's say OX, OY are the original (random positions) of the movie clips. If you haven't stored these in variables, do so, first thing:
OX = movie._x;
OY = movie._y;
Let's say TX, TY are the positions you want the movie clips to end up.
At any point in time:
movie._x = OX + (TX - OX)*R/100;
movie._y = OY + (TY - OY)*R/100;
This is actually simpler if, instead of computing R as a percentage (which goes from 0-100) you compute R as a ratio (which goes from 0-1). This basically means don't multiply by 100 when you compute R. Then formula simplifies to:
movie._x = OX + (TX - OX)*R;
movie._y = OY + (TY - OY)*R;
-
hmm
i think i get what you are saying. basically this is what i have for the random movement of one of my movieclips.
OX = this._x;
OY = this._y;
loading = _parent.getBytesLoaded();
total = _parent.getBytesTotal();
percent -= (percent-((loading/total)*100))*.25;
R = int(percent);
acceleration = 10
newpos = function () {
ranx = Math.round((Math.random ()*920));
rany = Math.round ((Math.random ()*520));
}
newpos();
this.onEnterFrame = function() {
this._x += ((ranx-this._x)/acceleration);
this._y += ((rany-this._y)/acceleration);
if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
newpos();
}
};
so this keeps it moving around, but when R (the loaded percentage) say is 25, i want the movieclip to move back to it's original OX and OY positions.
im having trouble introducing the "if" situation for
if (R=25) {the movieclip moves from ranx/rany to OX/OY}
does that make any sense? i'm getting confused myself.
thanks for helping me out.
-
Code:
var numClips : Number = 12;
var clip : MovieClip;
for(var i = 0; i < numClips; i++) {
clip = _root.createEmptyMovieClip("clip" + i, i);
clip.lineStyle(50, Math.random() * 0xFFFFFF, 50);
clip.moveTo(25, 25);
clip.lineTo(26, 25);
clip.createTextField("label", 1, 15, 15, 20, 20);
clip.label.text = i;
clip.label.autoSize = "center";
clip._x = Math.random() * Stage.width;
clip._y = Math.random() * Stage.height;
clip.xHome = Stage.width * (i % 4) / 4;
clip.yHome = Stage.height * Math.floor(i / 4) / 3;
clip.xv = clip.yv = 0;
clip.triggerPoint = i / numClips;
clip.onEnterFrame = wanderAround;
}
function wanderAround() {
this.xv += Math.random() * 2 - 1;
this.yv += Math.random() * 2 - 1;
this._x += this.xv;
this._y += this.yv;
if(this._x > Stage.width || this._x < 0) this.xv *= -1;
if(this._y > Stage.height || this._y < 0) this.yv *= -1;
if(pctLoaded > this.triggerPoint) {
this.onEnterFrame = goHome;
}
}
function goHome() {
this._x = (5 * this._x + this.xHome) / 6;
this._y = (5 * this._y + this.yHome) / 6;
if(Math.abs(this._x - this.xHome) > 1) return;
if(Math.abs(this._y - this.yHome) > 1) return;
this._x = this.xHome;
this._y = this.yHome;
delete this.onEnterFrame;
}
var pctLoaded : Number = 0;
this.onEnterFrame = function() {
pctLoaded += .002;
if(pctLoaded >= 1) delete this.onEnterFrame;
}
Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|