View Full Version : If noKey.isDown?
Press_Tilty
July 4th, 2009, 06:43 PM
I have my hero, and hes got standing, moving, and jumping frames.
When I do Key.RIGHT or Key.LEFT, it goes to moving, and Key.UP for jumping. How do I get it to return to standing if no key is pressed. (Or alternativley, have the frame only there while it is down). Thanks a lot!
Press_Tilty
therobot
July 4th, 2009, 06:54 PM
I have my hero, and hes got standing, moving, and jumping frames.
When I do Key.RIGHT or Key.LEFT, it goes to moving, and Key.UP for jumping. How do I get it to return to standing if no key is pressed. (Or alternativley, have the frame only there while it is down). Thanks a lot!
Press_Tilty
You may want to look at Key events. This is taken directly from adobe's site:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
};
keyListener.onKeyUp = function() {
trace("UP -> Code: "+Key.getCode()+"\tASCII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
};
Key.addListener(keyListener);
Essentially, the two events, onKeyDown and onKeyUp will tell you when a key is pressed, and released 8)
Press_Tilty
July 4th, 2009, 06:56 PM
hey, also, how can a do a good jump code (ive got touchingGround bool from another tutorial, but it won't work)?
you know, with out being able to triple jump.
therobot
July 4th, 2009, 07:02 PM
hey, also, how can a do a good jump code (ive got touchingGround bool from another tutorial, but it won't work)?
you know, with out being able to triple jump.
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
switch(Key.getCode())
{
case UP : // up is a constant for the key code for the up key
jump();
break;
}
};
Key.addListener(keyListener);
function jump():Void
{
if ( alreadyJumping == false ){
alreadyJumping = true;
// activate jumping code!
}
}
function jumpFinished():Void
{
// finish up the jump
alreadyJumping = false;
};
Press_Tilty
July 5th, 2009, 08:57 PM
is that code as2 or 3?
bluemagica
July 5th, 2009, 09:04 PM
that's as2, since its using object listeners, but that's more like pseudo code rather than something you can test out right away, so it dosen't matter much what version it is, just learn from its logic!
As for your very first question, logically i just check if all the action keys are not pressed, then i stand, like
if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && ...jump,move,whatever else you have....)
{
this.gotoAndStop("stand");
}
flyingmonkey456
July 5th, 2009, 09:08 PM
both of these are as2, but it should be easy to convert.
I have my hero, and hes got standing, moving, and jumping frames.
When I do Key.RIGHT or Key.LEFT, it goes to moving, and Key.UP for jumping. How do I get it to return to standing if no key is pressed. (Or alternativley, have the frame only there while it is down). Thanks a lot!
Press_Tilty
onClipEvent(load){
var upkey = false;
var downkey = false;
var leftkey = false;
var rightkey = false;
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
upkey = true;
}else{
upkey = false;
} if(Key.isDown(Key.DOWN)){
downkey = true;
}else{
downkey = false;
} if(Key.isDown(Key.LEFT)){
leftkey = true;
}else{
leftkey = false;
} if(Key.isDown(Key.RIGHT)){
rightkey = true;
}else{
rightkey = false;
}if(upkey == false){
if(downkey == false){
if(leftkey == false){
if(rightkey == false){
gotoAndStop(1); //change 1 to your standing frame
}
}
}
}
}
hey, also, how can a do a good jump code (ive got touchingGround bool from another tutorial, but it won't work)?
you know, with out being able to triple jump.
this will give your jump a decay rate so it's speed will decrease until it is moving down. it looks very realistic.
on(load){
var jumpmax = 10;
var jumpspeed = 0;
var jumpdecay = .5;
var jumping = false;
var gravity = 10;
var ground = 400; //whatever the ground is set as, you'll want to change this
}on(enterFrame){
if(character._y < ground){
character._y += gravity;
}if(character._y> ground){
character._y = ground;
}if(Key.isDown(Key.SPACE)){
if(jumping == false){
jumping = true;
jumpspeed = jumpmax;
}if(jumping == true){
ground = 1000;
character._y -= jumpspeed;
jumpspeed -= jumpdecay;
}if(jumpspeed <= -10){
jumping = false;
}if(jumping ==false){
jumpspeed = 0;
}
}
you mentioned triple jump. do you want double jumping? i could add that to the code pretty easily.
bluemagica
July 5th, 2009, 09:30 PM
You know, there's a big, bright edit button up there, and you are supposed to use it when you plan on spamming with two,three posts in a row! You are a senior user, please behave like one, and help keep the forum clean!
bluemagica
July 5th, 2009, 09:58 PM
hmm, ok I guess showing off is more important to you than helping others! i guess I can't do anythign about people like you....sigh!
flyingmonkey456
July 5th, 2009, 10:04 PM
i deleted my extra posts just to make you happy :)
now delete yours before people think you're talking to yourself
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.