Skip to content

Passing analog normalized value #2

@doubleactii

Description

@doubleactii

I propose allowing the module to pass down the normalized ranges of the analog in its onMove event.

This range would be from -1 to 1 in both axes.
The axis being targeted would have to be passed down so that the proper range can be sent to the proper axis.

This is how the Gamepad API works as well and is the inspiration for this change.

This would allow a user of the Gamepad API to turn around and also use this module and not have to change the inner workings of their code, as the same data would be passed from the controller and the joystick.

This will be a breaking change as API will be changed.

Example

import { MobileHandler } from './modules/mobile-handler.min.mjs';

const walkHandler= (pAxisName, pValue, pAngle, pRepeat) => {
	if (pAxisName === 'x' || pAxisName === 'y') {
		// Do something when a joystick moves its analogs
		handleVelocity(pAxisName, pValue, pAngle, pRepeat);
	}
}

const joyController = MobileHandler.createController({ 
        // ...
	'callback': {
		'onMove': walkHandler
	}
});

This is the proposed API change.

pAxisName Is the axis of the joystick that is targeted. x for left and right, y for north and south.
pValue Is the normalized range of the analog. -1 to 1 range. Where -1 is left, 0 is center, and 1 is right.
pAngle This is already an arg we pass down. The angle of the joystick.
pRepeat If the pValue has changed in this event since the last event then pRepeat will return false. Otherwise, it will return true to indicate the value is still the same, and if you want to waste processing on updating the state with the same information again.

Metadata

Metadata

Assignees

Labels

Priority: MediumAn issue with medium priority.Status: To doA planned feature.Type: DetailedAn issue that is well expressed and well detailed, may also have a test project attached.Type: EnhancementA request for a new feature.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions