-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controller support #416
base: master
Are you sure you want to change the base?
Controller support #416
Changes from 1 commit
f34a14b
29c3904
78dabad
dfd54b8
0effb6d
78cc4f5
748da8a
f3bc168
6206403
70b757e
f10a3fc
6b04ff8
696f78f
30f4e99
c135992
56ac855
001b79b
b518ba0
b9914b3
12e50c2
a2af537
0ffd77c
03137c5
b0ccbdb
fd2cc74
b6e0f25
82dfef6
b6778db
03487ae
3551e18
f91d79f
6ef7f6d
76135f5
d8032c5
6885cea
6d768a6
6b8b15d
fe8d3c8
40f01e4
c072ba8
4215c58
8b62d3b
a2b1f7d
a135d94
c9bfde5
3a1754a
ff4057b
2d706a4
15e9c52
60cf8cd
5433661
f381a85
341ac6d
0c76016
d1f8545
6bbad7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { ItemType, type ItemDefinition } from "@common/utils/objectDefinitions"; | |
import { Vec } from "@common/utils/vector"; | ||
import $ from "jquery"; | ||
import nipplejs, { type JoystickOutputData } from "nipplejs"; | ||
import * as PIXI from "pixi.js"; | ||
import { isMobile } from "pixi.js"; | ||
import { getTranslatedString } from "../../translations"; | ||
import { type Game } from "../game"; | ||
|
@@ -342,6 +343,50 @@ export class InputManager { | |
shootOnRelease = false; | ||
}); | ||
} | ||
const ticker = new PIXI.Ticker(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
ticker.stop(); | ||
ticker.add(() => { | ||
const gamepads = navigator.getGamepads(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you really need to call this method every frame, is it required? |
||
if (gamepads[0]) { | ||
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const leftJoystickMoving = gamepads[0].axes[0] !== 0 || gamepads[0].axes[1] !== 0; | ||
const rightJoystickMoving = gamepads[0].axes[2] !== 0 || gamepads[0].axes[3] !== 0; | ||
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// const rightJoystickDistance = Math.sqrt(gamepads[0].axes[2] * gamepads[0].axes[2] + gamepads[0].axes[3] * gamepads[0].axes[3]); | ||
// distance formula for stuff like throwables, USAS-12, and M590M | ||
if (leftJoystickMoving) { | ||
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const movementAngle = Math.atan2(gamepads[0].axes[1], gamepads[0].axes[0]); | ||
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.movementAngle = movementAngle; | ||
this.movement.moving = true; | ||
// note: movement.moving only works on mobile | ||
if (!rightJoystickMoving) { | ||
this.rotation = movementAngle; | ||
this.turning = true; | ||
const activePlayer = game.activePlayer; | ||
if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { | ||
game.activePlayer.container.rotation = this.rotation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't there a better way to do this in the |
||
this.turning = true; | ||
} | ||
if (!activePlayer) return; | ||
activePlayer.images.aimTrail.alpha = 0; | ||
} | ||
} else { | ||
this.movement.moving = false; | ||
} | ||
|
||
if (rightJoystickMoving) { | ||
this.rotation = Math.atan2(gamepads[0].axes[3], gamepads[0].axes[2]); | ||
this.turning = true; | ||
const activePlayer = game.activePlayer; | ||
|
||
if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && activePlayer) { | ||
Arman-AIi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
game.activePlayer.container.rotation = this.rotation; | ||
} | ||
|
||
if (!activePlayer) return; | ||
activePlayer.images.aimTrail.alpha = 1; | ||
} | ||
} | ||
}); | ||
ticker.start(); | ||
} | ||
|
||
private handleInputEvent(down: boolean, event: KeyboardEvent | MouseEvent | WheelEvent): void { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not import everything from pixijs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, now it only imports ticker