Fix brush on mobile
This commit is contained in:
parent
058d6014b7
commit
a7b14b9fbb
1 changed files with 11 additions and 5 deletions
|
|
@ -36,7 +36,7 @@ export default class GameLoop {
|
|||
private readonly canvas: HTMLCanvasElement,
|
||||
private readonly device: GPUDevice
|
||||
) {
|
||||
const context = this.canvas.getContext('webgpu') as any;
|
||||
const context = this.canvas.getContext('webgpu') as any as GPUCanvasContext;
|
||||
context.configure({
|
||||
device: this.device,
|
||||
format: navigator.gpu.getPreferredCanvasFormat(),
|
||||
|
|
@ -82,15 +82,17 @@ export default class GameLoop {
|
|||
return;
|
||||
}
|
||||
|
||||
this.brushPipeline.addSwipe(
|
||||
vec2.fromValues(event.clientX, this.canvas.height - event.clientY)
|
||||
const position = vec2.fromValues(
|
||||
event.clientX * this.devicePixelRatio,
|
||||
this.canvas.height - event.clientY * this.devicePixelRatio
|
||||
);
|
||||
this.brushPipeline.addSwipe(position);
|
||||
}
|
||||
|
||||
private resize() {
|
||||
const devicePixelRatio = window.devicePixelRatio || 1;
|
||||
this.canvas.width = this.canvas.clientWidth * devicePixelRatio;
|
||||
this.canvas.height = this.canvas.clientHeight * devicePixelRatio;
|
||||
this.canvas.width = this.canvas.clientWidth * this.devicePixelRatio;
|
||||
this.canvas.height = this.canvas.clientHeight * this.devicePixelRatio;
|
||||
}
|
||||
|
||||
private async render(time: DOMHighResTimeStamp) {
|
||||
|
|
@ -167,4 +169,8 @@ export default class GameLoop {
|
|||
private get canvasSize(): vec2 {
|
||||
return vec2.fromValues(this.canvas.width, this.canvas.height);
|
||||
}
|
||||
|
||||
private get devicePixelRatio(): number {
|
||||
return window.devicePixelRatio || 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue