Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,518 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,746 people online right now. Registration is fast and FREE... Join Now!




keyPress

 
Reply to this topicStart new topic

keyPress, Help please

Sonastylol
15 Aug, 2008 - 10:19 PM
Post #1

D.I.C Head
**

Joined: 15 Dec, 2007
Posts: 124


My Contributions


Hi guys, I know all about key.isDown (65) or whatever...

but I can't seem to get keyPress working.

on (keyPress "<Left>")
{
this._alpha -= 10;
}

works no problem. How do I make it work with a non-named key, such as A, which is 65

on (keyPress 65) doesnt work, neither does on(keyPress "65") , neither does on (keyPress "A")

What is the syntax?

User is offlineProfile CardPM
+Quote Post

BetaWar
RE: KeyPress
16 Aug, 2008 - 06:50 AM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
That actually does work if you want "A" to be pressed (Shift+"A"), but since I am pretty sure you are going for wasd direction controls and not the lettter "A" you have to do it like os:

CODE
on(keyPress "a"){
    trace("a");
}


Works in Flash 8, AS 2.0

Hope tha thelps.
User is offlineProfile CardPM
+Quote Post

Sonastylol
RE: KeyPress
16 Aug, 2008 - 07:23 AM
Post #3

D.I.C Head
**

Joined: 15 Dec, 2007
Posts: 124


My Contributions
Betawar,

Im trying to get my character to jump ONLY when you press Up.

I DONT want the player to be able to "bounce" the character by HOLDING up.

This is currently my jump code.

CODE
//Up Arrow
        if (Key.isDown(38) && _root.ground.hitTest(_x, _y+3, true)) {
            // Press W to jump ONLY when touching ground.
            grav = -jumpHeight;
            // makes gravity negative jumpheight, causes jump
            _y -= 4;
            // makes the y go up by 4
            this.gotoAndStop(2);
            // Enter Jump stance.
        }


Im getting frustrated because I set the game up to allow only single jumping at first ( with a fuel bar ), then upgrade to allow double jumping/triple jumping.

I can't seem to do it with Up Arrow tho. If I press Up arrow, not only will he jump, he'll deplete the fuel tank because onClipEvent(enterFrame) registers the keys being down WAY too fast. I want the character to have to single hit Up to jump once and only once.


To fix this problem with the depletion of fuel without getting a double jump, I have made A the double jump button ( only usable in air ). How do I make it work with one button? I already tried an if statement inside an if statement, it still registers 2 presses of Up arrow in like .000005 of a second.


heres an example.
http://www.spotlightcontest.com/adventure.html

please note that you can only double jump once ( with A ) once now because the fuel system IS working
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: KeyPress
16 Aug, 2008 - 07:46 AM
Post #4

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 times
Dream Kudos: 1175
My Contributions
I would suggest coming out with something a little different than placing your controls within an onEnterFrame function, try creating a key listener (like so):
CODE
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
    if (Key.isDown(Key.RIGHT)) {
        circle_mc._rotation += 5;
    }
    if (Key.isDown(Key.LEFT)) {
        circle_mc._rotation -= 5;
    }
};
Key.addListener(keyListener);


and placing your controls inside it.

Then to make it so you can jump multiple times try something like so:

CODE

var jumps:Number = 0;
var max_jumps = 1; // can only jump 1 time

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
  if(Key.isDown(Key.UP)){
    if(jumps < max_jumps){
            grav = -jumpHeight;
            _y -= 4;
            this.gotoAndStop(2);
       if(jumps > 1){
         // fuel -= amount here
       }
       jumps++;
    }
  }
};
Key.addListener(keyListener);


And then have it so when the character hits the ground it sets jumps = 0;

When the placer gets the upgrade your jump abilities all you have to do is update the max_jups variable.

Hope that helps.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 09:17PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month