00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

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!

(REPOST) how do i make a character move when a key is pressed but not holding the key?

495 Views | 6 Replies
New Topic Respond to this Topic

im using actionscript 2.0, in flash 8, so can anyone help me?


At 8/4/23 11:13 AM, SuperGibaLogan wrote: im using actionscript 2.0, in flash 8, so can anyone help me?

Use the keyUp clip event or listener if you want it to be triggered only once.

onClipEvent(keyUp) {
    trace(Key.getCode())
}

But if you want it to be triggered only once and when it is pressed (not released), then set a boolean to true when it is pressed.

onClipEvent(load) {
    this._key_pressed = false
}
onClipEvent(keyDown) {
    if (this._key_pressed == false) {
        trace('key pressed: ' + Key.getCode())
        this._key_pressed = true
    }
}
onClipEvent(keyUp) {
    this._key_pressed = false
}

Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

thanks, but how do i use it in a script tho?


also, can you please send me a full script like this, but with the script you replied with? to make my character move forever when a key is only pressed?


here is the script:


onClipEvent(enterFrame) {

if(Key.isDown(Key.LEFT)) {

this._x -=5;

}

if(Key.isDown(Key.RIGHT)) {

this._x +=5;

}

if(Key.isDown(Key.UP)) {

this._y -=5;

}

if(Key.isDown(Key.DOWN)) {

this._y +=5;

}

}


just replace the "this._x +=5;" or "this._y +=5;" parts with your script, thanks!


At 8/4/23 05:03 PM, SuperGibaLogan wrote: thanks, but how do i use it in a script tho?


You can create a variable like "_X_key_pressed" for each key you want to have pressed, or use an Object to store those details - and then use an IF condition to check whether those keys have been pressed or not.


At 8/4/23 05:10 PM, SuperGibaLogan wrote: also, can you please send me a full script like this, but with the script you replied with? to make my character move forever when a key is only pressed?

Two things:

  1. I won't program your game for you, and
  2. "Making the character move forever when a key is only pressed" is very different from the title of the question. Including the original answer in your script would have the character move only once when a key was pressed.

Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

At 8/4/23 11:13 AM, SuperGibaLogan wrote: im using actionscript 2.0, in flash 8, so can anyone help me?


can someone also tell how to do this but in construct 2?


my website roombaclock (google.com)

u\petir_greffin i'm peeking at you from my forum signature >:D

BBS Signature

alright, thanks