Controller Input:
I actually had some stuff for a contoller input tutorial written up already, so I figured I'd post it. (Feel free to add to this BlackAura)
With newer versions of KOS (up to 1.2.0), you have two methods you can choose from for controller input. Both are very similar, and easy to understand. First I will tell what is the same between the two, and then get into the differences.
Button Codes:
Both methods of polling the controllers (for lack of a better term), use the same button names. They are self explanatory, and listed below:
Most common:
Code: Select all
CONT_A
CONT_B
CONT_X
CONT_Y
CONT_START
CONT_DPAD_UP
CONT_DPAD_DOWN
CONT_DPAD_LEFT
CONT_DPAD_RIGHT
Here are a few others that don't appear on most controllers, but still can be used:
Code: Select all
CONT_C
CONT_D
CONT_Z
CONT_DPAD2_UP
CONT_DPAD2_DOWN
CONT_DPAD2_LEFT
CONT_DPAD2_RIGHT
Remember, all the button codes are used in both methods of controller polling.
Now lets move on to some differences:
Method 1: The old Maple API:
This method of controller input uses the older Maple API of KOS. This method is slightly easier (no use of pointers, one less function call), but may not be available in future versions of KOS. This is, by far, the most common way you will see controller code, as of right now.
To hold the controller information, we need a simple variable. This is a cont_cond_t in this case.
Will get a variable set up for you.
Now, to see what's being pushed, and react to it, you would put the following code in your game's main loop:
Code: Select all
cont_get_cond(maple_first_controller, &cond);
if(!(cond.buttons & CONT_A)) {
/* Do anything that needs to be done for pressing the A button here */
}
/* Put any buttons you will need in here, just like the A one above */
This just grabs what is being pushed on the 1st controller, and puts it in our variable we set up. All you have to do is test that variable for what ever button constant you want, as directed above. Simple, eh?
Method 2: The new Maple API:
This next method of controller polling relies on the new Maple API in newer versions of KOS. I believe that this API was available beginning with KOS 1.1.8, but I'm not positive.
This method involves two different variables, and is slightly easier to deal with multiple variables. Here are our two variables:
Code: Select all
cont_state_t * state;
maple_device_t * addr;
Our cont_state_t pointer will hold what buttons are pushed, and the maple_device_t pointer will point to a Maple address.
Before we try to get controller info, we need to initialize the address variable. This is done like so:
Code: Select all
addr = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
This will set the address variable to point to the first found Maple device that reports itself as a controller. You can change the 0 in the function to allow for other controllers to be used, just make sure to have multiple address variables.
Now to poll the controllers, put the following code in your game's main loop:
Code: Select all
state = maple_dev_status(addr);
if(state->buttons & CONT_A) {
/* Do any A button stuff here */
}
Once again feel free to add other buttons, and take A out. Just make sure they all look similar to the code snippet above.
That's all for right now, because I can't think of anything else to say! Feel free to leave any comments/questions and I'll try to remember to respond.