# MX pong game

**URL:** <https://forum.kirupa.com/t/mx-pong-game/8385>\
**Category:** flash\
**Created:** [November 19, 2002, 10:54pm UTC](https://forum.kirupa.com/t/mx-pong-game/8385 "2002-11-19T22:54:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![fez](https://avatars.discourse-cdn.com/v4/letter/f/7ab992/32.png) [@fez](https://forum.kirupa.com/u/fez)\
**Post date:** [November 19, 2002, 10:54pm UTC](https://forum.kirupa.com/t/mx-pong-game/8385/1 "2002-11-19T22:54:43Z")

</div>

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!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 19, 2002, 10:59pm UTC](https://forum.kirupa.com/t/mx-pong-game/8385/2 "2002-11-19T22:59:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 19, 2002, 11:39pm UTC](https://forum.kirupa.com/t/mx-pong-game/8385/3 "2002-11-19T23:39:42Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 19, 2002, 11:41pm UTC](https://forum.kirupa.com/t/mx-pong-game/8385/4 "2002-11-19T23:41:07Z")

</div>

Could u attach the fla for testing purposes?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 12:33am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/5 "2002-11-20T00:33:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 12:44am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/6 "2002-11-20T00:44:04Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 12:52am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/7 "2002-11-20T00:52:01Z")

</div>

Is this what you are looking for?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 12:53am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/8 "2002-11-20T00:53:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 12:56am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/9 "2002-11-20T00:56:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 1:09am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/10 "2002-11-20T01:09:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 20, 2002, 1:17am UTC](https://forum.kirupa.com/t/mx-pong-game/8385/11 "2002-11-20T01:17:00Z")

</div>

aha. understood now. thanks a lot.
