KeyPress MovieClip Continous Motion

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

This belongs in the Flash MX forum…

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.

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.

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.

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:

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

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:

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.

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:) :slight_smile: :slight_smile:

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

anything else you need… just let us know.

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…