Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-28-2007, 09:45 PM   #1
Registered User
Join Date: Jun 2007
Posts: 31
Default help with simple jumping code

Hey guys, ive ooked at the other threads for platformers and stuff but its nto quite answering my questions...

See i havent made a game in flash in.. well im going to say years. Last thing i touched to make a game was FlashMX. Anyways, back in the day i did all sorts of little games from platforming engines, to AI crowd simulations, and even attempting to make an FPS engine in flash. Glory days of lore. With years of being away i have ..REALLY lost my touch and im trying to get back into the swing of things. I use Flash CS3 but id liek to stick to AS2.0 and below as much as possible with this one.

..so i seem to have typed a little mini biography or somethign please ignore it if you dont care, haha.

So im trying to make a little game that resembles the Fusion Frenzy game "Twisted" in which a character is running at a constant speed, no control over this. The background is whats really moving. There are only 2 controls: Jump & Duck.

I have zero problems with the collision detection of objects and the ducking code, but i seem to be having a hell of a time getting jumping to work.

onClipEvent (load) {
	var yPos = this._y;
onClipEvent (enterFrame) {
	if (_root.jumping == false) {
		if (Key.isDown(Key.UP)) {
			// This just plain doesn't work
			while(this._y<(yPos-30)) {
			// this jumps him up WAY too quickly all at once
			for(i=0;i<30;i++) {
			//hmm this only moves with keyboard interaction at all times...
			if (this._y != yPos-30) {
Id like to be able to have him jump up using purely code while his timeline plays his jumping action. My old method of doing this was making an AS file with something like
and using the
#IMPORT "jump.as"
on every frame during his jumping sequence, but thats VERY hack and i dont want to use that. (i will if i have too lol)

Any ideas?
KyleHarrison is offline   Reply With Quote
Old 06-29-2007, 03:18 PM   #2
Ferrets &amp; Programming
Join Date: Mar 2007
Location: Ferret Paradise
Posts: 21

Here's what I did with my game that needed jumping:

ActionScript Code:
onClipEvent (load) {     var yPos = this._y; } onClipEvent (enterFrame) {      if(jumping == true){           this._y -= jumprate;           jumprate --;           //soon jumprate here will be negative, and that will make your guy fall back down.           //Add your collision detecting for the ground here, and if it did touch the ground:           jumping = false;           this.gotoAndPlay("seqRun");      }     if (_root.jumping == false) {         if (Key.isDown(Key.UP)) {             this.gotoAndPlay("seqJumping");             jumping = true;                                       jumprate = 20;                                       //jumprate controls how high and fast he'll jump.             }     } }

Just change jumprate and how fast it decreases for it to work in your game. See, what you did was make it do ALL the jumping RIGHT ONCE the button was pressed. In this, it moves the jump along every time the frame refreshes. Hope this helped!

Last edited by Ferret; 06-29-2007 at 03:25 PM.
Ferret is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] code for simple button bashing game rudutdo Gaming and Game Development 7 03-29-2007 09:04 PM
Simple code for Invisible buttons/MCs focus97 ActionScript 2.0 1 01-17-2007 08:56 PM
simple code don't work, why? nurgle ActionScript 2.0 2 08-24-2005 02:28 PM
Can anyone tell me why this simple code does not work? Andy S ActionScript 2.0 0 07-22-2004 09:30 PM
this simple code should work, right? maxx ActionScript 1.0 (and below) 11 04-10-2003 04:34 AM

All times are GMT. The time now is 07:23 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.