-
jumping on a slope!
I have this rather cool code for a _mc on a slope. The only problem I am having is making the sprite.mc change states/animation when the sprite.mc is jumping. Can you help? duh...
here's the code I have:
onClipEvent(load){
speed = 5;
gravity = 0;
r = _height/2; //radius
jumping = false;
jumpingheight = 15;
}
onClipEvent(enterFrame){
if(key.isDown(key.RIGHT)){
_x + =speed;
}
if(key.isDown(key.LEFT)){
_x - =speed;
}
if(key.isDown(key.UP) &&! jumping){
jumping = true;
gravity = -jumpheight;
}
if(!_root.ground.hitTest(_x,_y, true)){
gravity++;
_y+ = gravity;
}else{
jumping =false;
gravity = 0;
}
while(_root.ground.hitTest(_x,_y-1+r,true)){
jumping = false;
_y--;
}
}
-
Can you explain a little more your problem? Don't understand what do you mean with "changing states/animation"?
I've created a circle with instance name "jumper" and and a rectangle at the bottom with instance name "ground" and added next code into actions layer:
PHP Code:
var speed = 5; var gravity = 0; var r = jumper._height/2; //radius var jumping = false; var jumpingheight = 15;
jumper.onEnterFrame = function() { if(Key.isDown(Key.RIGHT)){ this._x+=5; } if(Key.isDown(Key.LEFT)){ this._x-=speed; } if((Key.isDown(Key.UP)) && (!jumping)){ jumping = true; gravity = -jumpingheight; } if(!ground.hitTest(this._x,this._y, true)){ gravity++; this._y += gravity; } else { jumping = false; gravity = 0; } while(ground.hitTest(this._x,this._y-1+r,true)){ jumping = false; this._y--; } }
Don't know if this helps you because, as I've mentioned above, I don't really understand what do you mean by "changing states/animation"...
P.S. If you want to add a smoother falling down and jumping up you can use a tweening class (for example caurina tweener - you can find it on the net).
Last edited by avukovi4; 12-18-2010 at 03:40 PM.
-
changing states
changing states, I mean: apart from using Left & Right keypresses, use control and shift to incorporate a 'duck' and 'roll' animation.
thanks for the kind reply.
bryan
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
|