Hmm! :)
Helped alot!
Hmm! :)
Helped alot!
I'm glad it did!
nice
how do i make it like punch and stuff real time battle
Animate a punch and use hitTest. Check out Platform Tutorial AS2 for more info.
Okay, Thanks a bunch
Great tutorial, not exactly what I needed but it still helped a lot. I'm gonna try (stress on try, I not the greatest programmer) and explain your 'unexplained code'.
Well, to me it seems that this code controls the 'random' movement that the health 'thingy' does by moving all over the place. I hope the comment box gives me the space to explain, of course in programming comment style, because it's easier that way. For those who don't know, // is the start of a comment, or /* comment */ also counts as a comment.
//Sorry, I can't really explain this part to you. (Original statement. by author.)
function getdistance(x, y, x1, y1) { //function that gets distance from two points.
var run, rise; // variables to be used.
run = x1-x; // this is basic math, rise over run, slope, duh? It uses the points
rise = y1-y; // -to get a slope.
return (_root.hyp(run, rise)); // calls another function in its return (the var it
} // back to the program, basic stuff) which finds the hypotenuse (actual line)
function hyp(a, b) { // The hypotenuse function, takes two vars; rise and run
return (Math.sqrt(a*a+b*b)); // finding the hypotenuse, distance formula duh
}
MovieClip.prototype.reset = function() { // okay, getting complicated here. A function, that when called, runs inside the MC, which is the health thingy.
//specify the width and height of the movie (Author)
width = 550;
height = 400;
//-------------------
var dist, norm; // two more variables.
this.x = this._x; // okay, this is object programming. Here it saves the x and y
this.y = this._y; // positions in memory, BASICALLY. To difficult to explain here.
this.speed = Math.random()*4+2; //makes a random speed. For your info, //Math.rand makes a number between 0-1, therefore, if Math.rand is 0.7, speed //is 0.7*4+2, about 4.8
this.targx = Math.random()*width; // okay, this gives the health thing a random //target, using random again, so if rand was 0.7 its x target is 385.
this.targy = Math.random()*height; // same thing for y.
dist = _root.getdistance(this.x, this.y, this.targx, this.targy); // remember the //function way at the top? This runs to get the line from its current position to //its 'target' position.
norm = this.speed/dist; // this makes a speed to travel down the line. (or up, etc)
this.diffx = (this.targx-this.x)*norm; // this finds the difference between current
this.diffy = (this.targy-this.y)*norm; // and target distance places.
};
MovieClip.prototype.move = function() { // this is actually going to MOVE the //health thingy.
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx; // remember that 'speed' (norm) we got before? This is going
this.y += this.diffy; // to move it at that speed, in the line's direction.
} else {
this.x = this.targx; // The part above only works if the distance is higher than the
this.y = this.targy; // speed, (if it's still on the line), else, we just go directly to its //target. We don't want it to move forever, right?
if (!this.t) { // um... I have no idea where this came from, but basically since //Booleans are true by default, this automatically works anyway.
this.t = getTimer(); // exactly what it sounds like, it creates a timer.
}
if (getTimer()-this.t>1000) { //when the timer reaches 1000 ( in milliseconds) we
// start the function for the beginning.
this.reset(); // From the beginning, that's what the reset is for.
this.t = 0; // timer goes to zero.
}
}
this._x = this.x; // we actual put the health where its supposed to be. This is
this._y = this.y; // object programming, so don't bother about it.
};
Yay, just 470 chars left! Well I hope that clears things up, I did the best I could. I want to thank the author, cause even though it wasn't exactly what I was looking for, I know how to make a timer now! Kudos.
Oh yeah, I forgot about that one part. It doesn't matter to me a whole lot, though, since I use a different bit of code for random movement which is actually more concise.
.......is good
Oh? Well thanks.
Good job
I'm not sure if I saw this before, I meant the "what we'll be making" demo thing, but it sure is useful, it's a wellmade tutorial.
One thing though, people who try to learn this stuff would like to know how to make all this scripting, so, usually, for all the noobs out there, it would be preferable if you put in explanations of what the scripts did and how it worked, not just a copy-[aste text box.
Good try though
EVERYONE IS SAYING THAT!!! Graaagh! I explain what it does! When I say:
onClipEvent(enterFrame){
I put a // after it to explain what it did!
onClipEvent(enterFrame){//Movie Clip handler
WILL YOU PEOPLE FINALLY UNDERSTAND THAT???
Sheesh...