Detect when a button is released #2

Closed
opened 2016-09-23 00:47:51 -07:00 by jalbam · 2 comments
jalbam commented 2016-09-23 00:47:51 -07:00 (Migrated from github.com)

Hello,

Thanks for this library. Seems great!

I do not have a Nintendo Wii right now with me so I cannot test anything. But reading the documentation and looking at the source code I do not see a way to check whether a button has been released or not. This is very important for games. I am developing a game engine framework that will probably use your library to support Wii if you do not mind (showing your name in the credits, of course).

The events are named "pressed_a", etc. but what about "released_a", etc.?

I need a way to access to every controller's object at any time and be able to check whether a chosen button (or even more than one) is being pressed or not. I am not sure, but I guess the "hold" property (from the "official" Wii JS API), which is a bitmask, could be useful here. But I cannot even find the official documentation about using JavaScript with the old Wii console (I can only find it about the new Wii U).

My idea is to have the following array (just a simplified example):

var wiimotes =
[
    {
        horizontal: true, //Are there any way to detect when this changes? I want to use horizontal by default.
        UP: true, //"true" means the button is being pressed.
        DOWN: false,
        LEFT: false,
        RIGHT: false,
        A: false,
        B: undefined, //"undefined" means the button status cannot be read.
        C: undefined,
        Z: undefined,
        "1": false,
        "2": false,
        "PLUS": false,
        "MINUS": false,
        roll: float?,
        distance: float?,
        x: float?,
        y: float?,
        ... //Maybe more properties.
    },
    ... //Three more objects with the same structure (because the total of possible controllers is four).
];

That array just holds all the possible four controllers as an object and every of those objects holds the status of the corresponding buttons. In the beginning, all values should be set to false/undefined. Now I want to use your library to update the array using the following way:

//Updating array for Wiimote 1:
var wiimote1 = new Wii.Remote(1, {horizontal: true});
wiimote1.when("pressed_up", function(wii_remote, wii_remote_status) { wiimotes[0].UP = true; }); //"UP" pressed.
wiimote1.when("pressed_down", function(wii_remote, wii_remote_status) { wiimotes[0].DOWN = true; }); //"DOWN" pressed.
//... (more events that would update the status of the rest of the buttons).

//... To update the array for the rest of the Wiimotes (2, 3 and 4), just proceed the same way.

Obviously, the code above could be in a loop for the four controllers. That is not important now.

Please, could you tell me how I could use your library to update the values of that array and set the buttons to "false" when the button is released?

I am sorry about the long message. Thank you very much for all!

Regards,
Joan

Hello, Thanks for this library. Seems great! I do not have a Nintendo Wii right now with me so I cannot test anything. But reading the documentation and looking at the source code I do not see a way to check whether a button has been released or not. This is very important for games. I am developing a game engine framework that will probably use your library to support Wii if you do not mind (showing your name in the credits, of course). The events are named "pressed_a", etc. but what about "released_a", etc.? I need a way to access to every controller's object at any time and be able to check whether a chosen button (or even more than one) is being pressed or not. I am not sure, but I guess the "hold" property (from the "official" Wii JS API), which is a bitmask, could be useful here. But I cannot even find the official documentation about using JavaScript with the old Wii console (I can only find it about the new Wii U). My idea is to have the following array (just a simplified example): ``` var wiimotes = [ { horizontal: true, //Are there any way to detect when this changes? I want to use horizontal by default. UP: true, //"true" means the button is being pressed. DOWN: false, LEFT: false, RIGHT: false, A: false, B: undefined, //"undefined" means the button status cannot be read. C: undefined, Z: undefined, "1": false, "2": false, "PLUS": false, "MINUS": false, roll: float?, distance: float?, x: float?, y: float?, ... //Maybe more properties. }, ... //Three more objects with the same structure (because the total of possible controllers is four). ]; ``` That array just holds all the possible four controllers as an object and every of those objects holds the status of the corresponding buttons. In the beginning, all values should be set to false/undefined. Now I want to use your library to update the array using the following way: ``` //Updating array for Wiimote 1: var wiimote1 = new Wii.Remote(1, {horizontal: true}); wiimote1.when("pressed_up", function(wii_remote, wii_remote_status) { wiimotes[0].UP = true; }); //"UP" pressed. wiimote1.when("pressed_down", function(wii_remote, wii_remote_status) { wiimotes[0].DOWN = true; }); //"DOWN" pressed. //... (more events that would update the status of the rest of the buttons). //... To update the array for the rest of the Wiimotes (2, 3 and 4), just proceed the same way. ``` Obviously, the code above could be in a loop for the four controllers. That is not important now. Please, could you tell me how I could use your library to update the values of that array and set the buttons to "false" when the button is released? I am sorry about the long message. Thank you very much for all! Regards, Joan
ryanmcgrath commented 2016-09-28 11:00:47 -07:00 (Migrated from github.com)

Heya,

Yeah, so you'd need to probably alter the library to...

  • For controller #1, just hook into DOM events for the up variant of events. Only controller 1 gets these for whatever reason.
  • For controllers #2-4, you'd probably need to rewire the Wii.listen event slightly to detect when a release has occurred.

The specifics of this would take me awhile to get back into as I've not touched the library in 5 years, but feel free to reach out again if you have issues!

Heya, Yeah, so you'd need to probably alter the library to... - For controller #1, just hook into DOM events for the `up` variant of events. Only controller 1 gets these for whatever reason. - For controllers #2-4, you'd probably need to rewire the `Wii.listen` event slightly to detect when a release has occurred. The specifics of this would take me awhile to get back into as I've not touched the library in 5 years, but feel free to reach out again if you have issues!
jalbam commented 2016-09-28 22:21:14 -07:00 (Migrated from github.com)

Hello again,

Thank you very much for your answer.

So I guess to access the controller #1 status we just need to manage the key events fired and the other controllers use the Nintendo Wii API in JavaScript to expose their status. I am not sure about that.

It is difficult to me to modify the library without knowing too much about the Nintendo WII API (I guess it can be similar to the WII U API which also uses bitmasks but not totally equal) and without having a real Nintendo Wii console to test, but if I find some time and an old console maybe I will try to do it (just need to know when buttons are released).

Thank you very much,
Joan

Hello again, Thank you very much for your answer. So I guess to access the controller #1 status we just need to manage the key events fired and the other controllers use the Nintendo Wii API in JavaScript to expose their status. I am not sure about that. It is difficult to me to modify the library without knowing too much about the Nintendo WII API (I guess it can be similar to the WII U API which also uses bitmasks but not totally equal) and without having a real Nintendo Wii console to test, but if I find some time and an old console maybe I will try to do it (just need to know when buttons are released). Thank you very much, Joan
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/wii-js#2
No description provided.