I've just made a new jumping engine. And, unlike all other jumping engines in this forum, this one doesn't have "_root.ground "in it. Infact, it has no required instance names other then "_root.circle" (which the object names itself as, so the user doesn't have to do anything). The advantage to this jumping engine is that you can have as many blocks for your character to land on as you want. And, it's so simple, even a n00b can use it without problems! Here it is:
Put this code in the character:
onClipEvent (load) {
fall = false;
_name = "circle";
jump = 0;
speed = 6;
jumpheight = 18;
maxfall = -54;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
}
------------------------------------
Put this code in any block:
onClipEvent (load) {
activated = false;
down = false;
}
onClipEvent (enterFrame) {
_root.report.text = Math.round(_root.circle.yMax)+" "+Math.round(yMin);
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
if (_root.circle.yMax-_root.circle.jump*2>yMin) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}
if (Math.round(_root.circle.yMax)>Math.round(yMin)) {
if (hitTest(_root.circle) && _root.circle.xmax<xmin) {
_root.circle._x -= _root.circle.speed;
---------------------------------------
That's IT! Now some of you may be even more interested in how I wrote this code. Well, here's some specs:
In itself, an object contains 6 properties:
(yMax + yMin)/2 = _y
yMax - yMin = _height
yMin - yMax = -_height
_height - yMax = -yMin
yMax - _height = yMin
yMin + _height = yMax
It can also be concluded that:
An object's size has no effect on it's _y value.
_height can never be a negative value, unlike _yscale.
yMin-yMax will always be negative, and yMax-yMin will always be positive.
---------------------------------
That's all for now. Now test my engine to see if it works. If so, gimmie some feedback.
Remember, you can use this to make multiple blocks, not just one called "_root.ground". BLOCKS DON'T NEED INSTANCE NAMES!
I really, really hope this works. It works fine for me.
}
if (hitTest(_root.circle) && _root.circle.xmin>xmax) {
_root.circle._x += _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
_root.circle.jump = -1*(_root.circle.jump);
}
}
if (activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
_root.circle.jump = 0;
activated = false;
}
if (hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
if (_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}