This commit is contained in:
Evert Prants 2022-04-09 15:58:16 +03:00
parent 6c0f6350d6
commit 5c043fb224
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
import { CanvasTexture, Sprite, SpriteMaterial } from 'three';
import { CanvasUtils } from './canvas-utils';
export class ChatBubble {
public tag!: Sprite;
public width!: number;
public height!: number;
private texture!: CanvasTexture;
private material!: SpriteMaterial;
constructor(private builder: CanvasUtils, private message: string[]) {
this.create();
}
create() {
const { texture, width, height } = this.builder.createTextCanvas(
this.message,
);
this.texture = texture;
this.width = width;
this.height = height;
this.material = new SpriteMaterial({
map: texture,
transparent: true,
});
const label = new Sprite(this.material);
const labelBaseScale = 0.01;
label.scale.x = width * labelBaseScale;
label.scale.y = height * labelBaseScale;
this.tag = label;
}
dispose() {
this.material.dispose();
this.texture.dispose();
}
}