MX pong game

i am trying to make a pong game using only hittests and variables to set the constant x movement of the ball. the code for the paddles works fine but the code for the ball doesnt.

onClipEvent (load) {
xspeed=14;
yspeed=7;
_root.ball._x += xspeed;
_root.ball._y += yspeed;
if (_root.ball, hitTest(_root.paddle)) {
_root.ball._y -= yspeed;
_root.ball._x += xspeed;
}
}

the problem is, when the ball hits the paddle, it works fine for one frame, and the ball looks as if to go up, but then it suddenly starts following its intial path.PLEASE HELP!!!

i know that the problem is very elementary but at the moment i cannot figure it out. btw i did not actually use onClipEvent(load)
i used enterFrame, just changed it for testing purposeds

what’s hapening is it sees the hit and does what’s in the if statement but then the if statement is no longer true so it goes back to what it was doing before. Would it be possible to put your hit test loop on the paddles and if it’s true then use

delete movieclip.onEnterFrame
movieclip.onEnterFrame = function(){
}

to set your clip event for the ball, that way you don’t have problems with 2 conflicting onClipEvent commands.

Could u attach the fla for testing purposes?

i think i get what youre saying. heres the fla anyway. the walls are there, but no hitTest actions on them yet.

could you maybe elaorate on that sorcerer? im not exactly a flash wiz. i tried a little of what you said and put the hit test on the paddle. the ball moves the way i want it to now, only porblem is, the paddle moves with it…

Is this what you are looking for?

almost there except i need the _y to decrease by seven also. that doesnt seem to be happenind

wait i think i got it, need to tweak the y value some. but do you think you could explain what exactly you did? im not entirely sure i understand

I think i got it, I removed your original ball clip event and put it on an actions layer.

What I did:
You had it so that it would increase the x value by 14 and decrease the y value by 7 when it detected a hit. The problem was it would only do this when there was a hit and so the ball would go back to it’s orignal x += 14, y+= 7 unless the hit test was true.

What I did was first used the command

delete _root.ball.onEnterFrame

this clears any onEnterFrame commands on that MC

Then I assigned a new onEnterFrame command to the ball movie clip using

_root.ball.onEnterFrame = function(){
}

this executes whatever you put inside the function tags every frame. so on each hit test you will need to use delete to get rid of the previous function and then assign a new one to make it do what you want.

aha. understood now. thanks a lot.