Keyboard events in editor
ullvieib

Hi!

Can´t find how to catch eg. if space is pressed.

I guess I use the background object and go to functions, onKeyDown.

Tried:

if(isKeyDown(32)){
    alert("test");
}
but it does not work.
 
 
/Birger
All 4 Comments
Shri

Ulvieib,

 

You have to do something like this

this.onKeyDown = function() {    if (wade.isKeyDown(32)) { alert('test'); }}; // end onKeyDown

So you catch the onKeyDown event before you check if a key is down.

 

If I might make a suggestion, if you check out some of the stuff in the projects area, a lot of you questions may be answered.

For example, I put up a gui example here gui demo

Also, there is a "full" game here rift runner

In the projects section, all the code is downloadable.

 

Also, if you look in the forums -> your games, there is also a lot of source code there too.

 

cheers,

Shri

ullvieib

Thank You Shri.

I have found a lot of code examples, but it is not always obvious where to put the code in the editor view.

And it is not an intuitive solution if I have to create a new function for onKeyDown in the editor area where I edit the function onKeyDown..

 

Thats life for a beginner!

 

Thank you again for your support.

/Birger

Gio

Hi

 

If using the editor, you shouldn't need to create a function manually, putting some code in the "onKeyDown" function should work. Can you try putting this in your background object's onKeyDown?

alert(JSON.stringify(data));

Your code above in the first post is almost fine, but I think you need to call wade.isKeyDown

 

Also you'll want to make sure that, in the object properties, Auto Listen is checked, which it is by default but if it wasn't checked that would explain why it didn't work.

 

Please let me know what happens if you use the code I suggested above - if it's a bug in the editor we'll need to get it fixed asap.

ullvieib

Hi!

alert(JSON.stringify(data)); gave:

 

{"keyCode":32,"shift":false,"ctrl":false,"alt":false,"meta":false}

 

Auto Listen is active

 

And this works!:

if(wade.isKeyDown(32)){
    alert("test");
}
 
Thank you Gio!!
Post a reply
Add Attachment
Submit Reply
Login to Reply