|
-
Walking animation 'on the spot' with certain key presses
Got it in the wrong forum last time...
I have a glitch in my code somewhere, and was wondering if one of you kind souls would help me.
I have a walking animation frame for a movieclip (frame 5), and a still frame for when it is not in motion (frame 1).
It all works fine, except for one small glitch.
If I hold RIGHT (for example), then release, it stops walking.
If I hold RIGHT, then hold UP, then release UP, then release RIGHT, it continues the walking animation but stops moving.
Any ideas?
Code:
onClipEvent (load) {
gotoAndStop(1);
leftpower = 12;
rightpower = 12;
uppower = 12;
downpower = 12;
}
onClipEvent (enterFrame) {
if (Key.isDown (Key.CONTROL))
{
keydown=true;
}
else
keydown=false;
if (Key.isDown(Key.LEFT)) {
_x -= leftpower;
gotoAndPlay(5);
this._xscale = -100;
}
if (Key.isDown(Key.RIGHT)) {
_x += rightpower;
gotoAndPlay(5);
this._xscale = 100;
}
if (Key.isDown(Key.CONTROL)) {
gotoAndPlay(12);
}
if (Key.isDown(Key.UP)) {
_y -= uppower;
gotoAndPlay(5);
}
if (Key.isDown(Key.DOWN)) {
_y += downpower;
gotoAndPlay(5);
}
if (_root.wall.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
leftpower = 0;
}
else {
leftpower = 12;
}
if (_root.bwall.hitTest(this.touch)) {
xspeed = 0;
yspeed = 0;
downpower = 0;
}
else {
downpower = 12;
}
if (_root.twall.hitTest(this.touch)) {
xspeed = 0;
yspeed = 0;
uppower = 0;
}
else {
uppower = 12;
}
if (_root.leadpipe.leadpipetouch.hitTest(this.touch)) {
_root.leadpipe._x = -1000
gotoAndPlay(5);
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.RIGHT) {
gotoAndPlay(1)
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.LEFT) {
gotoAndPlay(1)
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.UP) {
gotoAndPlay(1)
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.DOWN) {
gotoAndPlay(1)
}
}
After playing about, I think I've narrowed it down to this (again, this is an example, because whether you press a combination of up, down, left, or right - the glitch still appears):
Code:
onClipEvent (keyUp) {
if (Key.getCode() == Key.UP) {
gotoAndPlay(1)
}
}
Works fine on its own, but when combined with right, for example, it doesn't seem to gotoAndPlay frame 1, it just continues to play frame 5.
I'm thinking maybe
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
|