oops
This commit is contained in:
parent
6c0f6350d6
commit
5c043fb224
42
src/client/object/chat-bubble.ts
Normal file
42
src/client/object/chat-bubble.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user