Right, so I’ve got this engine down:
(filler graphics for now).
EDIT: Arrow keys to move, a to jump.
It seems fine at first, but as you can see, if you jump with a platform overhead, you get stuck in that platform - that happens because the registartion point of the mc (the ‘+’) is at the feet of the character. It needs to be this way so that it registers on the ground.
The code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) && !_root.bg.hitTest(_x-20, _y, true)) {
this._x -= walkSpeed;
} else if (Key.isDown(Key.RIGHT) && !_root.bg.hitTest(_x+20, _y, true)) {
this._x += walkSpeed;
}
if (Key.isDown(65) && _root.bg.hitTest(_x, _y+4, true)) {
ySpeed = -20;
}
if (!_root.bg.hitTest(_x, _y+ySpeed+3, true)) {
ySpeed += 2;
_y += ySpeed;
} else if (ySpeed>0) {
while (ySpeed>0 && _root.bg.hitTest(_x, _y+ySpeed, true)) {
ySpeed--;
}
_y += ySpeed;
ySpeed = 0;
}
}
onClipEvent (load) {
ySpeed = 0;
}
onClipEvent (load) {
speed = 5;
}
EDIT: That doesn’t show up for me. So here’s the code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) && !_root.bg.hitTest(_x-20, _y, true)) {
this._x -= walkSpeed;
} else if (Key.isDown(Key.RIGHT) && !_root.bg.hitTest(_x+20, _y, true)) {
this._x += walkSpeed;
}
if (Key.isDown(65) && _root.bg.hitTest(_x, _y+4, true)) {
ySpeed = -20;
}
if (!_root.bg.hitTest(_x, _y+ySpeed+3, true)) {
ySpeed += 2;
_y += ySpeed;
} else if (ySpeed>0) {
while (ySpeed>0 && _root.bg.hitTest(_x, _y+ySpeed, true)) {
ySpeed–;
}
_y += ySpeed;
ySpeed = 0;
}
}
onClipEvent (load) {
ySpeed = 0;
}
onClipEvent (load) {
speed = 5;
}
I’ve got the scrolling code below that, but that doesn’t interfere.
Any body got any ideas on how to fix this? I’ve tried (It’s now the 20th, the latest update was on the 11th) for 9 days to fix this, and failed. Any help?
Cheers.