PDA

View Full Version : _x _y movement help



ToXic
July 18th, 2005, 11:50 PM
I was reading this very good tutorial on gravity and making an object bounce.
http://www.bit-101.com/tutorials/gravity.html

After I played around with it, I wanted to add more circles on the stage to make 'em bonce too, but then I couldn't, because it would move along with the first circle all the way, like it was stuck to it. Then I noticed on the code how it messes around with the _x _y properties... but then I thought, _x and _y coordinates of what?! This symbol, the other one... that other one..?!? Can somebody explain this better?
Let's say I wanted to add that code to 8 balls so they all bounce? How would I do it? Thnx.

stringy
July 19th, 2005, 12:32 AM
I was reading this very good tutorial on gravity and making an object bounce.
http://www.bit-101.com/tutorials/gravity.html

Let's say I wanted to add that code to 8 balls so they all bounce? How would I do it? Thnx.
looks like the code was written for flash5
heres same code to mx
remove all code you have +only need 1 frame
8 mcs on the Stage instance names mc1,mc2.......
on the frame

rightedge = 550;
leftedge = 0;
topedge = 0;
bottomedge = 400;
gravity = 2;
drag = .98;
bounce = .9;
for (var i = 1; i<9; i++) {
var clip = this["mc"+i];
clip.xspeed = Math.random()*60-30;
clip.yspeed = Math.random()*60-30;
clip.onEnterFrame = move;
clip.onPress = mypress;
clip.onRelease = clip.onReleaseOutside=myrelease;
}
function move() {
if (!this.dragging) {
this._x = this._x+this.xspeed;
if (this._x+this._width/2>rightedge) {
this._x = rightedge-this._width/2;
this.xspeed = -this.xspeed*bounce;
}
if (this._x-this._width/2<leftedge) {
this._x = leftedge+this._width/2;
this.xspeed = -this.xspeed*bounce;
}
this._y = this._y+this.yspeed;
if (this._y+this._height/2>bottomedge) {
this._y = bottomedge-this._height/2;
this.yspeed = -this.yspeed*bounce;
}
if (this._y-this._height/2<topedge) {
this._y = topedge+this._height/2;
this.yspeed = -this.yspeed*bounce;
}
this.yspeed = this.yspeed*drag+gravity;
this.xspeed = this.xspeed*drag;
} else {
this.xspeed = this._x-this.oldx;
this.yspeed = this._y-this.oldy;
this.oldx = this._x;
this.oldy = this._y;
}
}
function mypress() {
this.startDrag();
this.dragging = true;
}
function myrelease() {
stopDrag();
this.dragging = false;
}

ToXic
July 19th, 2005, 01:03 AM
Hey! Thanks alot that code's really helpful2 me at the moment so thnx!!

stringy
July 19th, 2005, 12:36 PM
Hey! Thanks alot that code's really helpful2 me at the moment so thnx!!

glad to help :)