Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # update method from the game scene
- update(time: number, delta: number) {
- const pointer = this.input.activePointer;
- if (pointer.isDown) {
- if (!this.isDrawing) {
- const line = new MyLine(this, pointer.x, pointer.y);
- this.add.existing(line);
- this.lines[line.getId()] = line;
- this.isDrawing = true;
- this.currentLineId = newCon.getId();
- } else if (this.isDrawing) {
- const curLine = this.lines[this.currentLineId];
- curLine.setTo(
- curLine.getPointA().x, curLine.getPointA().y,
- pointer.x, pointer.y
- )
- curLine.draw();
- }
- } else if (this.isDrawing) {
- this.isDrawing = false;
- }
- if (this.sKey && this.sKey.isDown && !this.curServer) {
- const pointer = this.input.activePointer;
- const circle = new MyCircle(this, pointer.x, pointer.y);
- this.add.existing(circle);
- this.circles.push(circle);
- this.curCircle = circle.getId();
- } else if (this.sKey && this.sKey.isUp && this.curCircle) {
- this.curCircle = undefined;
- }
- }
- export class Resource extends GameObjects.Graphics {
- protected id: string;
- constructor(scene: Scene) {
- super(scene)
- this.id = uuid();
- }
- getId() {
- return this.id;
- };
- }
- export class MyCircle extends Resource {
- constructor(scene: Scene, x: number, y: number) {
- super(scene);
- this.setX(x);
- this.setY(y);
- this.clear();
- this.lineStyle(5, 0x1E90FF, 1.0);
- this.fillCircle(0, 0, 20);
- }
- }
- export class MyLine extends Resource {
- line: Geom.Line;
- constructor(scene: Scene, x1?: number, y1?: number, x2?: number, y2?: number) {
- super(scene);
- this.line = new Geom.Line(x1, y1, x2, y2);
- }
- getPointA() {
- return this.line.getPointA();
- }
- draw() {
- this.clear();
- this.lineStyle(5, 0xFF00FF, 1.0);
- this.strokeLineShape(this.line);
- return this;
- }
- setTo(x1: number, y1: number, x2: number, y2:number) {
- this.line.setTo(x1, y1, x2, y2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement