# KeyPress MovieClip Continous Motion

**URL:** <https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059>\
**Category:** random\
**Created:** [May 29, 2003, 4:12pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059 "2003-05-29T16:12:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ironzionmarley](https://avatars.discourse-cdn.com/v4/letter/i/6a8cbe/32.png) [@ironzionmarley](https://forum.kirupa.com/u/ironzionmarley)\
**Post date:** [May 29, 2003, 4:12pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/1 "2003-05-29T16:12:23Z")

</div>

I searched the forums and found nothing in this topic so if someone has already posted sometihng like this I didnt do it on purpose. I can get my MC to move on my keypresses with the D-Pad but when I press a direction, I want it to keep going at that increment until I press a different direction. Basically I want a PacMan like movement so my game player doesnt get finger cramps. Gracias

---

<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:** [May 29, 2003, 4:16pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/2 "2003-05-29T16:16:51Z")

</div>

This belongs in the Flash MX forum…

---

<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:** [May 29, 2003, 4:50pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/3 "2003-05-29T16:50:35Z")

</div>

I’m working on a pacman myself. This is how mine works.

I have a pacman movie clip with an instance name “pacMan” on the main timeline. It has this script attached to it.

```auto
onClipEvent(enterFrame){
	this._x+=this.xSpeed;
	this._y+=this.ySpeed;
	if(this._x>_root.stageWidth){
		this._x=0;
	}else if(this._x<0){
		this._x=_root.stageWidth;
	}else if(this._y>_root.stageHeight){
		this._y=0;
	}else if(this._y<0){
		this._y=_root.stageHeight;
	}
}

```

then I have a button on the main timeline with this action attached to it.

```auto
on(keyPress "<Left>"){
	_root.pacMan._rotation=180;
	_root.pacMan.ySpeed=0;
	_root.pacMan.xSpeed=-5;
}
on(keyPress "<Up>"){
	_root.pacMan._rotation=280;
	_root.pacMan.ySpeed=-5;
	_root.pacMan.xSpeed=0;
}
on(keyPress "<Right>"){
	_root.pacMan._rotation=0;
	_root.pacMan.ySpeed=0;
	_root.pacMan.xSpeed=5;
}
on(keyPress "<Down>"){
	_root.pacMan._rotation=90;
	_root.pacMan.ySpeed=5;
	_root.pacMan.xSpeed=0;
}

```

I’m sure that there are a few ways of doing this though.

---

<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:** [May 29, 2003, 5:55pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/4 "2003-05-29T17:55:49Z")

</div>

Hey thanks so much but I have one more question, what is the button of? Is it an inv button? And also my pacman has limitations like i cant go past a certain spot, but I am wondering if thats because of the button. Thanks though for what you posted. Helped so freakin much. You=:pope:

---

<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:** [May 29, 2003, 6:35pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/5 "2003-05-29T18:35:25Z")

</div>

[www.lexgraphics.com](http://www.lexgraphics.com)

if it is then i will explain how to accomplish

i use the key.isPressed feature instead of keyPress

because kepress will occur once, then a delay is made and then it repeats… which is not good because it depends on the keyboard setting, you can change the delay and the repeat speed so in a game it would be consistent.

check out that bug game at [lexgraphics.com](http://lexgraphics.com) and chek out how the bug has continuous movement as soon as u press the key and for as long as the key is pressed…

i iwll teahc u how if u request it… bye bye:pope:

---

<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:** [May 30, 2003, 2:28am UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/6 "2003-05-30T02:28:24Z")

</div>

Hey man, I dont quite want to do that. See in your game you have it so you have to hold down the key. What I am looking for is a one press action so when you hit right once, it will continue going right until another direction is pressed. Thanks though, and by the way I played your game a while, high score is 6.004 seconds. Peace:) oh, and if you do know how to action script the method i described, that would help :beam:

---

<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:** [May 30, 2003, 8:43am UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/7 "2003-05-30T08:43:05Z")

</div>

The button that I have is an invisible one, yes. I forgot to mention that I set a variable on the \_root timeline called stageWidth and another called stageHeight, and in the case of this example was using 400 by 400 stage demensions.

first frame, main timeline

stageHeight=400;  
stageWidth=400;

In additionto that, my pacman is facing to the right, when animated normaly, hence the \_rotation modifier. It’s set to make him look like he’s eating “up” when moving up, eating “left” when moving left, etc.

---

<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:** [May 30, 2003, 12:50pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/8 "2003-05-30T12:50:42Z")

</div>

OMG. Thank you so much dude. You have no idea how badly I needeed that. Thank you for your help, the PacMan workd great now. And by the way, the way you type out your tutorials is very easy to read and organize. Good job! Thank you:) 🙂 🙂

---

<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:** [May 30, 2003, 12:58pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/9 "2003-05-30T12:58:02Z")

</div>

Thank you for the comps. I try hard to be clear to the lowest common denominator.

anything else you need… just let us know.

---

<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:** [June 3, 2003, 9:07pm UTC](https://forum.kirupa.com/t/keypress-movieclip-continous-motion/22059/10 "2003-06-03T21:07:14Z")

</div>

hey , thanks for playing the game man… i got a 4.293 once… not because it was my game , but because the random balls were arranged easily one time. sooo…
