Ok first off, HI!!! My name is Jeff Snow. You all can call me Dryst or jeff, whatever.
Ive been browsing these tutorials and message boards for a few weeks, so here I am :).
Ok heres the problem
I made this Ball+Gravity thing, and now I want to add a Hoop and have it keep score. I know about the _root.total = _root.total + 1; part of the code, but how would I go about making it only work if the ball goes through the net from the top.
And what extra code would I have to add to make the net play a little movie clip animation when the ball passes through?.
Well if you had an mc called hop (just the top rim), you could use:
if (_root.ball.hitTest(_x, _y, true)) {
_root.score++
}
So when the ball goes through the center of the hoop (providing that’s where the registration point is) the score will increase. But you need to set it so that the score only increases upon the first contact, and not repeated contacts (otherwise the score will continue increasing as it’s going “through” the hoop) - which isn’t too difficult to do, but also have it so that the score dosn’t increase when the hit test is true if the ball bounces back up.
You can also use a hit test to make sure that the ball only register a score when it drops from the top and not just hitting the hoop sideways.
Also use !drag - drag = false - (if you use drag as a variable to set whether the balls is being dragged or not) so that you can’t cheat and just drag the ball through.
It sounds like an interesting idea and if I get a mo, I’ll try and do a fla. unless someone already has, or has better ideas.
I think the ball needs to be tagged ‘ball’ or something, I think the rest of the code is fine, its just not understanding what the ball part is in (_root.ball.hitTest ect…)
The ball is a movie clip, the movie clip is named ball. the balls code is this
onClipEvent (load) {
gravity = 2;
floor = 383;
floorx1 = 17;
floorx2 = 533;
bounce = 0.80;
speedx = 0;
speedy = 0;
}
onClipEvent (enterFrame) {
if (pressing) {
// if we are pressing
// drag the object
startDrag (this, true);
// calculate the speed
speedx = this._x-x0;
speedy = this._y-y0;
// set a new reference point
x0 = this._x;
y0 = this._y;
} else {
stopDrag ();
speedy = speedy+gravity;
this._x += speedx/7;
this._y += speedy/7;
if (this._y>floor) {
this._y = floor;
speedy *= -bounce;
}
if (this._x<floorx1) {
this._x = floorx1;
speedx *= -bounce;
}
if (this._x>floorx2) {
this._x = floorx2;
speedx *= -bounce;
}
}
}
Possibly add a small invisible box on the outer sides of the hoop and code it to react with the ball using something similar to the bounce code on the ball?
I thought off the net alread! I’m trying little bits here and there while I drink my pepsi and munch chocolate. That part is easy.
The rim - just put a movie clip there and have it so that if the ball hits, the _x and _y are reversed so it bounces off.
The drag one needs a variable.
But you also need to either increase the size of the ball, decrease the size of the hoop, or increase the hit area, because _x, _y in the hit test works if the ball goes the centre of the hoop, but the ball is small so it still goes through - even though it’s not in the centre, and no score is registered.