00:00
00:00
Newgrounds Background Image Theme

FylypFimpossible just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

I've made a jumping engine for all.

48,479 Views | 365 Replies
New Topic Respond to this Topic

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;
}
}

Response to I've made a jumping engine for all. 2004-07-23 22:33:22


AHHHHHHHHHHHHH! MISTAKE! THE BLOCK CODE IS ACTUALLY THIS:

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;
}
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;
}
}

Response to I've made a jumping engine for all. 2004-07-23 22:45:15


Nice job Rystic, n00bs are gonna flood the portal with side scrolling platformers. lol, it's an awesome code man.

Response to I've made a jumping engine for all. 2004-07-23 22:47:01


At 7/23/04 10:45 PM, Deathcon7 wrote: Nice job Rystic, n00bs are gonna flood the portal with side scrolling platformers. lol, it's an awesome code man.

thnx... it was hard to make.. but i did it...

Response to I've made a jumping engine for all. 2004-07-24 00:23:05


hmm this is wierd because when I tested this code out ( i made a stick man and two little platforms) and i made the guy and the platforms MC's but when I add the code and check my syntaxes it has errors and says that onClipEvent can only be used in movie clip instances. So what could I have done wrong? Everything IS a MC

Response to I've made a jumping engine for all. 2004-07-24 07:07:44


At 7/23/04 11:57 PM, PillowBiter wrote: heres a platformer script (WITH SCROLLING (cool looking)

You miss the point of this. There aren't suppose to be clip names. That way, you can make as many blocks as you like, not just one called ground.

Response to I've made a jumping engine for all. 2004-07-24 07:09:11


At 7/24/04 12:23 AM, t4int3d_s0ul wrote: hmm this is wierd because when I tested this code out ( i made a stick man and two little platforms) and i made the guy and the platforms MC's but when I add the code and check my syntaxes it has errors and says that onClipEvent can only be used in movie clip instances. So what could I have done wrong? Everything IS a MC

I posted the wrong block code. Check out my second post in this thread to see the correction. Also, make sure these are in two seperate movie clips.

Response to I've made a jumping engine for all. 2004-07-24 07:37:42


Thanks Rystic ! ! !
I was making a platform game before, but when i made multiple platforms, the character sometimes fell through. In combination with some hittests, your code is superior !
Thanks again i'm really really glad this finally works !!

Response to I've made a jumping engine for all. 2004-07-24 08:11:06


That's a great code! Maybe now my games won't suck as much anymore.


fucking magnets man how do they work

Response to I've made a jumping engine for all. 2004-07-24 08:32:18


ooooh guys... looks difficult^^


XO

Response to I've made a jumping engine for all. 2004-07-24 09:26:16


At 7/24/04 07:37 AM, cuber3 wrote: Thanks Rystic ! ! !
I was making a platform game before, but when i made multiple platforms, the character sometimes fell through. In combination with some hittests, your code is superior !
Thanks again i'm really really glad this finally works !!

No problem, man. I've worked on perfecting this jump engine for awhile, and I'm glad I can finally share it with the NG community.

Response to I've made a jumping engine for all. 2004-07-24 09:27:57


At 7/24/04 08:32 AM, molkman wrote: ooooh guys... looks difficult^^

Don't worry... I made it so simple, even a newbie can use it. No instance name requirements. Isn't that great?

Response to I've made a jumping engine for all. 2004-07-24 09:33:42


Nice work man. Looks like a lot of hard work had been put in. But I go for art based collision detection.

Response to I've made a jumping engine for all. 2004-07-24 10:15:19


Looks nice, for some reason I'm too much of a moron to get it to work :D. But it's possible to create a platformer with having instance names......

Response to I've made a jumping engine for all. 2004-07-24 10:52:21


If i jump onto the same block again, my MC falls right through it. I am using the second code part..

Response to I've made a jumping engine for all. 2004-07-24 10:52:29


eerr...i tryed useing this and all the charictor does is jump....not when u press a button, but constantly...what am i doing wrong?

Response to I've made a jumping engine for all. 2004-07-24 10:53:49


Jumping works fine here?

Response to I've made a jumping engine for all. 2004-07-24 11:16:43


I'dd prefer something like my rogerjump game, or www.di-m.de/runner.swf :-) Still i find it a great Idea that you made this code which does not require any naming, so every beginner can use it... Though I still dont get why i am falling through a block unless i jump on a different one first.

Response to I've made a jumping engine for all. 2004-07-24 14:13:11


At 7/24/04 10:52 AM, schorhr wrote: If i jump onto the same block again, my MC falls right through it. I am using the second code part..

Hmmm... that doesn't make sense. E-mail your FLA to me (if you want) and I'll take a look at it.

Also, this would be a good time to address anyone who wants to modify the code: you are allowed to, but e-mail me first and tell me what your updating.

Rystic_Force@hotmail.com

Response to I've made a jumping engine for all. 2004-07-24 14:14:31


At 7/24/04 10:52 AM, -Ercle- wrote: eerr...i tryed useing this and all the charictor does is jump....not when u press a button, but constantly...what am i doing wrong?

I don't know why people are having problems. I tested this code over and over. Tell me, are you using movie clips AND the correct code?

Response to I've made a jumping engine for all. 2004-07-24 14:17:13


ANYONE WHO HAS PROBLEMS GIVE ME YOUR E-MAILS AND I WILL SEND YOU THE WORKING FILE

That should do it...

Response to I've made a jumping engine for all. 2004-07-24 14:18:41


I'm trying to dig up errors in this engine so I can fix them, too. If you encounter any errors, e-mail me the FLA (if you want to) or, if your an actionscripter, try modifying the code then mailing it to me. Thanks!

Response to I've made a jumping engine for all. 2004-07-24 14:49:50


At 7/24/04 02:27 PM, TheAlmightyChet wrote: This doesn't seem to work for me...
Posted a link to download the fla HERE.

Your problem is that you moved the insides of the MC around. For some reason that messes it up. Go inside the clip and move it down a bit (until it works). Also, you can't have diagonal blocks; only horizontal and vertical.

Response to I've made a jumping engine for all. 2004-07-24 15:01:01


At 7/24/04 02:54 PM, TheAlmightyChet wrote: Right then, I remade the character MC, but it still doesn't seem to work :\

Now you've moved it down too far. Try centering the body on the + sign thingie (this thing is wokring for me). It works when it is centered.

Response to I've made a jumping engine for all. 2004-07-24 15:06:46


At 7/24/04 03:03 PM, TheAlmightyChet wrote: Oh yeah, it works. Thankee!

No problem, dude. And thank you for addressing this issue, which I believe others are struggling with. When you first make a MC, it is automatically centered. If you move it, however, this engine won't work. Moral: finalize your pictures before making them clips!

Response to I've made a jumping engine for all. 2004-07-24 15:32:43


I have switched the settings so the default is not centered, due to my RPG /so the center is at the bottom / the feet ).

Response to I've made a jumping engine for all. 2004-07-24 16:02:30


Could you guys plz tell me how to work this. i m a huge n00b

Response to I've made a jumping engine for all. 2004-07-24 16:08:34


Draw a guy. Select it all, rightclick-> convert to symbol-> movieclip, name doesnt matter.

Now click the guy once, go to actions (F8 key) and paste the stuff inside.
Same with the wall code.

Response to I've made a jumping engine for all. 2004-07-24 16:15:23


ok i do that and it says there is ten errors

Response to I've made a jumping engine for all. 2004-07-24 16:19:17


Let me guess...

"OnClipEvent.... can only be used in movieclips" or something?

You must click the movieclip, if you dont you will post it into a key frame.
See picture:

I've made a jumping engine for all.