Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Joystick.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ const joystickStories = storiesOf('Joystick Examples', module);


joystickStories.add("Default joystick", () => <Joystick start={action("Started")} move={action("Moved")}
stop={action("Stopped")}/>);
stop={action("Stopped")} />);

joystickStories.add("Default joystick with small stick", () => <Joystick stickSize={10} start={action("Started")} move={action("Moved")}
stop={action("Stopped")}/>);
joystickStories.add("Default joystick with 50% minDistance", () => <Joystick minDistance={50} start={action("Started")} move={action("Moved")}
stop={action("Stopped")}/>);
joystickStories.add("Default joystick with base click", () => <Joystick start={action("Started")} move={action("Moved")}
stop={action("Stopped")} baseClick={true} />);
joystickStories.add("Control plane override", () => <Joystick start={action("Started")} controlPlaneShape={JoystickShape.Square} move={action("Moved")}
stop={action("Stopped")}/>);
joystickStories.add("Square joystick", () => <div style={{display:'flex', justifyContent:'space-around', padding:'25px'}}><Joystick throttle={100} start={action("Started")} baseShape={JoystickShape.Square} stickShape={JoystickShape.Square} move={action("Moved")}
Expand Down
9 changes: 9 additions & 0 deletions src/Joystick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IJoystickProps {
stickImage?: string;
baseImage?: string;
followCursor?: boolean;
baseClick?: boolean;
baseShape?: JoystickShape;
stickShape?: JoystickShape;
controlPlaneShape?: JoystickShape;
Expand Down Expand Up @@ -117,6 +118,10 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {

componentDidMount() {
this._mounted = true;
if (this.props.baseClick) {
this._baseRef.current?.addEventListener(InteractionEvents.PointerDown, event => this._pointerDown(event));
}

if (this.props.followCursor) {
//@ts-ignore
this._parentRect = this._baseRef.current.getBoundingClientRect();
Expand Down Expand Up @@ -200,8 +205,12 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
distance: null,
direction: null
});

}

if (this.props.baseClick) {
this._pointerMove(e);
}
}

/**
Expand Down