I'm having problems of the mouse controlled paddle being able to appear on the other side of the ball. The paddle's Y movement is controlled by the mouse, but the X is animated on mouseclick at a different frame rate than the ball.
I am rewriting to use a "delta" timer so I thought I would put this out there so I have some more ideas when I get back to it.
So the paddle's y is set by a MouseMove event, the paddle's x is set by a 15ms timer based on a long switch statement based on the png frames:
I move the ball like this every 30ms:
footX = NaN;
footX = -24;
footX = -23;
footX = -21;
then check for collisions with the paddles (I think I am going to rewrite this to check row x first then hitTestPoint individual paddles)
private function move():void
ball.x += ball.speedX;
ball.y += ball.speedY;
I then calculate the angle and bounce it off that side. but if the paddle moves too fast it can pass over without colliding. Could anyone help suggest a more accurate method?
footGlobal = team.men[i].localToGlobal(regPoint);
footGlobal.x += table.team1.footX;
ballGlobal = ball.localToGlobal(regPoint);
dx = ballGlobal.x - footGlobal.x;
dy = ballGlobal.y - footGlobal.y;
dist = Math.sqrt(dx * dx + dy * dy);
minDist = ball.radius + 15;
if (dist < minDist)
collide(team.men[i], footGlobal, dx, dy);
Also, is it bad practice to have objects running at different frame rates?