-
Hi,
I have a boxing game, where the player has the option of using the keyboard or buttons to control their boxer. In the player's boxer MC, I have:
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
which allows the player to control their boxer's movements smoothly. My question is, how can I achieve this same smooth movement (i.e. '+= moveSpeed' ) via the buttons? Right now, all I've got inside the buttons is:
on (press) {
setProperty ("_root.boxer", _x, x+10);
(where x = getProperty ("_root.boxer", _x).
This just moves the boxer in short 10 pix. increments when the button is pressed. I'd like to be able to move the boxer more smoothly, without stopping, until the button is released.
I know there's got to be a pretty simple solution. I'm just not gettin' it. Any help on this is much appreciated. Thanks.
-
change ("_root.boxer", _x, x+10); to
("_root.boxer", _x, x+1);
the lower the number, the slower the boxer will go, but the smoother it will go. I think.....
-
Thanks for your help. Only problem is that now it only moves in 1 pix. increments whenever the button is pressed. The player needs to continually click on the button to get the boxer to move. What I'd like to be able to do is, whenever the button is pressed and held down, the boxer moves smoothly in that direction without stopping, until the button is released. There's got to be a way to do this. Thanks again, Anti-Matter0.
-
I understand your problem. I think if you make a MC Trigger that will continually reload (aka frame 2 actions goto and play frame 1) and tell the button to make that trigger play when pressed, it will work. so on button press tell target moverighttrigger-play on button release, release outside, drag outside tell target moverighttrigger gotoandstop frame 1.
sorry about the unofficial actionscript, this computer doesnt have flash
-
Here! I made a tutorial for you. It should work. There is one problem that you might want to ask someone else about. When the button is pushed, the Boxer moves to the very edge of the screen, after that it works fine though. It might be an error in my coding (Forgive me, I'm only in 9th grade).
Here's the file: download "Boxermove1.fla"
http://opticaldelusion.8m.com/sentry_attack.html
-
Look at the actions of the button and of the second frame of the trigger. THayt's where most of it happens. I can't understand why he jumps to the edge of the screen.....
Mad-Sci or Froth probably know.
-
This is what you need to do:
have your boxer mc with these modified actions:
onClipEvent (enterFrame) {
if (key.isDown(key.RIGHT)) {
_root.moveright = true
}
if (key.isDown(key.LEFT)) {
_root.moveleft = true
}
if (key.isDown(key.DOWN)) {
_root.moveup = true
}
if (key.isDown(key.up)) {
_root.moveup = true
}
if (_root.moveright) {
this._x += moveSpeed;
} else if (_root.moveleft) {
this._x -= moveSpeed;
}
if (_root.movedown) {
this._y += moveSpeed;
} else if (_root.moveup) {
this._y -= moveSpeed;
}
}
then on your buttons have your actions like this:
on(press) {
_root.moveup = true
}
on(release) {
_root.moveup = false
}
modify those actions for each different button.
Hope that helps!
-
Senior Member
try this...
rather then moving once with a step of 10 try moving 10 times with step of 1
mad_sci
PS in my foter the ball moves 18 times with a step of one..gives you a realy smooth move..
mad_sci
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|