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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/*
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './joy';
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './joy';
121 changes: 121 additions & 0 deletions dist/joy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export interface StickStatus {
xPosition: number;
yPosition: number;
x: number;
y: number;
cardinalDirection: CardinalDirection;
}
export type CardinalDirection = "C" | "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW";
interface JoyStickMembers {
title: string;
width: number;
height: number;
internalFillColor: string;
internalLineWidth: number;
internalStrokeColor: string;
externalLineWidth: number;
externalStrokeColor: string;
autoReturnToCenter: boolean;
context: CanvasRenderingContext2D;
canvas: HTMLCanvasElement;
circumference: number;
internalRadius: number;
maxMoveStick: number;
xCenter: number;
yCenter: number;
movedX: number;
movedY: number;
pressed: boolean;
callback: JoyStickCallback;
stickStatus: StickStatus;
}
export interface JoyStickParameters extends Partial<JoyStickMembers> {
}
export type JoyStickCallback = (stickStatus: StickStatus) => void;
export declare class JoyStick {
private title;
private width;
private height;
private internalFillColor;
private internalLineWidth;
private internalStrokeColor;
private externalLineWidth;
private externalStrokeColor;
private autoReturnToCenter;
private callback;
private objContainer;
private context;
private canvas;
private circumference;
private internalRadius;
private externalRadius;
private maxMoveStick;
private centerX;
private centerY;
private directionVerticalLimitPos;
private directionVerticalLimitNeg;
private directionHorizontalLimitPos;
private directionHorizontalLimitNeg;
private pressed;
private movedX;
private movedY;
private stickStatus;
constructor(containerId: string, parameters?: JoyStickParameters, callback?: JoyStickCallback);
/**
* @desc Draw the external circle used as reference position
*/
private drawExternal;
/**
* @desc Draw the internal stick in the current position the user have moved it
*/
private drawInternal;
/**
* @desc Events for manage touch
*/
private onTouchStart;
private onTouchMove;
private onTouchEnd;
/**
* @desc Events for manage mouse
*/
private onMouseDown;
private onMouseMove;
private onMouseUp;
getCardinalDirection(): CardinalDirection;
/**
* @desc The width of canvas
* @return Number of pixel width
*/
getWidth(): number;
/**
* @desc The height of canvas
* @return Number of pixel height
*/
getHeigh(): number;
/**
* @desc The X position of the cursor relative to the canvas that contains it and to its dimensions
* @return Number that indicate relative position
*/
getPosX(): number;
/**
* @desc The Y position of the cursor relative to the canvas that contains it and to its dimensions
* @return Number that indicate relative position
*/
getPosY(): number;
/**
* @desc Normalizzed value of X move of stick
* @return Integer from -100 to +100
*/
getX(): number;
/**
* @desc Normalizzed value of Y move of stick
* @return Integer from -100 to +100
*/
getY(): number;
/**
* @desc Get the direction of the cursor as a string that indicates the cardinal points where this is oriented
* @return String of cardinal point N, NE, E, SE, S, SW, W, NW and C when it is placed in the center
*/
getDir(): CardinalDirection;
}
export default JoyStick;
Loading