|
|
|
#1 |
|
Member
Join Date: Aug 2003
Location: Australia
Posts: 38
|
how to use other keys for "key.isDown" function
hi,
im trying ot make some games, and use keys to do stuff, as most games do, and i can only seem to use the arrows or function keys (tab, pgdn, delete, space, etc) and i'm wondering, how can i set it up to use keys like w, s, a and d? thanks
__________________
T-Roy |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
Try the following frame script in frame 1:
In the keyDown event you can look at either Key.getAscii() - which will give you printable characters, or Key.getCode() which will get you arrows and other special keys. Here's another version of the onKeyDown handler which uses two switch statements and is a little more elegant:
You can also make an event handler for onKeyUp as well. Last edited by jbum; 10-18-2004 at 11:45 PM. |
|
|
|
|
|
#3 |
|
Member
Join Date: Aug 2003
Location: Australia
Posts: 38
|
looks good, i'll have a crack at it later, thanks for ur help!
__________________
T-Roy |
|
|
|
|
|
#4 |
|
Member
Join Date: Aug 2003
Location: Australia
Posts: 38
|
i tried that. didn't work for what i needed. i used this bit:
if (Key.getAscii() == ord('w')) { speed += 1; } but as soon as you press W, the car acts as if you dropped a brick on the accelerator and just keeps going. same with turning, u press A for left and it just spins around. i need something like: if (Key.isDown(getAscii() == ord('w'))){ speed += 1; } so that it doesn't keep going, as it checks if the key is down. i tried putting an else thing after that if, to make it slow down if W is not pressed, but no luck. thanks guys
__________________
T-Roy |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
Sounds like you're working on the same assignment as this guy:
http://www.flashkit.com/board/showth...hreadid=590525 His movie, with corrections applied, has a pretty good framework for moving a car. The trick is applying a damping factor when the key is NOT being held down: speed *= 0.9; |
|
|
|
|
|
#6 |
|
Member
Join Date: Aug 2003
Location: Australia
Posts: 38
|
would i do the dampening thing using else{ ? cos i think i tried that, it didn't seem to do nething. cos that means if its not going fowards, slow down. im not sure exactly what im getting up, but whatever i did didn't work.
flash needs to just be able to do if {Key.isDown(key.W)) etc etc. just use normal letters and not have to do the ascii crap. damn flash, its gr8, but could be so much better!
__________________
T-Roy |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Aug 2006
Posts: 3
|
Ascii Multiple Keys
Is there any way to get flash to detect more than one ascii key at once?
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Aug 2006
Posts: 3
|
Anybody?
|
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Aug 2006
Posts: 3
|
you can use:
Code:
if(Key.isDown(code:number)){
}
Code:
if(Key.isDown(87)){
}
|
|
|
|
|
|
#10 |
|
14yr old Member
Join Date: Jun 2007
Location: Santa Cruz CA
Posts: 272
|
i know
put this code into a movie clip and press any key to fing the code onClipEvent(keyDown) { trace("Key Pressed" + Key.getCode()); } this code will help 65 = a key if(Key.isDown(65 && 83){ //do something } it sais that if the a and s key are down it does something if you want an or statement replace the && with || and if the a or s key is down do something |
|
|
|
|
|
#11 |
|
Member
Join Date: Sep 2008
Posts: 36
|
Code:
onClipEvent(enterFrame) {
if (Key.isDown(65)) {//==Key.LEFT
this._x-=3;//or something else...
}
if (Key.isDown(67)) {//==Key.RIGHT
this._x+=3;//or something else...
}
if (Key.isDown(87)) {//==Key.UP
this._y-=3;//or something else...
}
if (Key.isDown(83)) {//==Key.DOWN
this._y+=3;//or something else...
}
}
A=65 B=66 C=67 D=68 E=69 F=70 G=71 H=72 I=73 J=74 K=75 L=76 M=77 N=78 O=79 P=80 Q=81 R=82 S=83 T=84 U=85 V=86 W=87 X=88 Y=89 Z=90 If you need more help with your games, just ask.... Last edited by fjodorvanveen; 12-05-2008 at 01:29 PM. Reason: forget code function |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|