[help]centering random rocks
I'm having problems with my ramdom rock generater. It makes all the rocks i need but, when I want to center them to get an even rotation it goes out of wack. how can i center the rocks to get the even rotation?
just copy past code in frame to work it
Code:
//total rocks at one time
totalrock = 10;
//rock id number
ir = 0;
//interval that puts out rocks
rocky = setInterval(this, "rockgen", 1000);
function rockgen() {
var done = false;
if (ir>=10) {
ir = 1;
}
while (ir<totalrock && !done) {
ir++;
if (this["rock"+ir] == null) {
done = true;
//create rock
this.createEmptyMovieClip("rock"+ir, ir);
//create rock drawing
this["rock"+ir].createEmptyMovieClip("p", 1);
//Rock drawing
this["rock"+ir].p.beginFill(0x333333, 100);
this["rock"+ir].p.lineStyle(3, 0x666666, 100);
//point x
this["rock"+ir].p.lineTo(0, 0);
//point 1
this["rock"+ir].p.lineTo(ran()+20, ran()+10);
//point 2
this["rock"+ir].p.lineTo(ran()+30, ran()+30);
//point 3
this["rock"+ir].p.lineTo(ran()+20, ran()+50);
//point 4
this["rock"+ir].p.lineTo(0, ran()+60);
//point 5
this["rock"+ir].p.lineTo((ran()+20)*-1, ran()+50);
//point 6 middle
this["rock"+ir].p.lineTo((ran()+30)*-1, ran()+30);
//point 7
this["rock"+ir].p.lineTo((ran()+20)*-1, ran()+10);
//point x
this["rock"+ir].p.lineTo(0, 0);
//Rock drawing end
//center code
this["rock"+ir].p._x = this["rock"+ir].p._width/2;
this["rock"+ir].p._y = this["rock"+ir].p._height/2;
this["rock"+ir]._x = int(Math.random()*400);
//rotation cw or ccw
var chosse = int(Math.random()*2);
switch (chosse) {
case 0 :
this["rock"+ir].rospeed = int(Math.random()*20);
break;
case 1 :
this["rock"+ir].rospeed = int(Math.random()*20)*-1;
break;
}
this["rock"+ir].onEnterFrame = function() {
var t = this;
t._y += 20;
t._rotation += t.rospeed;
if (t._y>Stage.width) {
removeMovieClip(t);
}
};
}
}
}
//retruns a random number
function ran() {
return int(Math.random()*5);
}
this is the code i use to center the rock
Code:
//center code
this["rock"+ir].p._x = this["rock"+ir].p._width/2;
this["rock"+ir].p._y = this["rock"+ir].p._height/2;