Why Joytest mix sincr/asincr reading pad and buttons?

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Why Joytest mix sincr/asincr reading pad and buttons?

Post by danibus » Thu Mar 07, 2019 11:44 pm

Just testing Sample/joystest

Use handleInput(); into main() loop, that means, every loop we enter this function to check UP,DOWN,LEFT,RIGHT

But use joyEvent() to check A,B,C,Start

Why?

I mean, I put UP,DOWN,LEFT,RIGHT into joyEvent() and only works 1 time when pressing button, I need to release it and push again
Why can't use async for every button?

that means in any shutmup I can't use joyEvent() to detect pushing fire button, if I want auto-fire

Not sure why SGDK works like this :?:

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by Chilly Willy » Fri Mar 08, 2019 5:11 pm

joytest is merely an example of reading the controllers, not the end-all/be-all of controller godhood. :D You can handle the controllers any way you wish. If registering an event handler would work better for your game, use that instead of directly reading the state. Reading the state was simply an easier way of doing the example which just shows the current state of the controllers. The event callback is called any time any button on any controller changes, so entering the handler, you know something changed, you just need to check what changed and do whatever you need to do on that button change.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by danibus » Fri Mar 08, 2019 11:13 pm

Thanks Chilli Willy.
How can I check, in a callback func, a button pressed without release-and-push-again?

bioloid
Very interested
Posts: 169
Joined: Fri May 18, 2012 8:22 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by bioloid » Sat Mar 09, 2019 12:58 pm


Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by Chilly Willy » Sat Mar 09, 2019 3:03 pm

danibus wrote:
Fri Mar 08, 2019 11:13 pm
Thanks Chilli Willy.
How can I check, in a callback func, a button pressed without release-and-push-again?
Look at the sprite example to see how you use the callback function.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by danibus » Sat Mar 09, 2019 11:41 pm

Chilly Willy wrote:
Sat Mar 09, 2019 3:03 pm
danibus wrote:
Fri Mar 08, 2019 11:13 pm
Thanks Chilli Willy.
How can I check, in a callback func, a button pressed without release-and-push-again?
Look at the sprite example to see how you use the callback function.
I saw before posting :D
joyEvent() : just check A, B and C buttons
handleInput() : just check D-PAD to move Sonic

I think 'problem' (is not really a problem) is that callback only is called when a change was done, in this case push RIGH and RELEASE
So If I push RIGH and don't release -> no change -> no more callbacks


PD: I prefer reading the state with handleInput() but I want to learn, so I ask

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by Chilly Willy » Sun Mar 10, 2019 3:23 pm

If you're looking for something like autofire, I'd set a flag in the event callback saying the fire button is pushed, then call the fire code periodically from the main loop where it checks the fire button flag. That seems like the easiest way to do autofire with joy events to me. So the joy events are asynchronous, but the firing is synchronous to the main loop at a set rate.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Why Joytest mix sincr/asincr reading pad and buttons?

Post by danibus » Sun Mar 10, 2019 5:25 pm

Thanks Chilly Willy

Post Reply