generated from remarkablegames/phaser-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gameobjects): modularize Circle from Main
- Loading branch information
1 parent
3a036b8
commit 06232d9
Showing
3 changed files
with
78 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Phaser from 'phaser'; | ||
|
||
import { _ } from '../constants'; | ||
|
||
const CIRCLE_CONTAINER = 'circles'; | ||
|
||
export class Circle extends Phaser.GameObjects.Arc { | ||
color: number; | ||
|
||
constructor(scene: Phaser.Scene, color: number) { | ||
const x = 0; | ||
const y = 0; | ||
const radius = 16; | ||
const startAngle = 0; | ||
const endAngle = 360; | ||
const anticlockwise = false; | ||
|
||
super(scene, x, y, radius, startAngle, endAngle, anticlockwise, color); | ||
scene.add.existing(this); | ||
|
||
this.color = color; | ||
|
||
const hasColor = color !== _; | ||
|
||
this.setOrigin(0.5) | ||
.setInteractive({ | ||
useHandCursor: true, | ||
}) | ||
.setActive(hasColor) | ||
.setVisible(hasColor); | ||
|
||
let container = getCircleContainer(scene); | ||
|
||
if (!container) { | ||
container = setCircleContainer(scene); | ||
} | ||
|
||
container.add(this); | ||
} | ||
} | ||
|
||
/** | ||
* Adds new circle container to scene. | ||
* | ||
* @returns - Circle container. | ||
*/ | ||
export function setCircleContainer(scene: Phaser.Scene) { | ||
const container = scene.add.container(); | ||
scene.data.set(CIRCLE_CONTAINER, container); | ||
return container; | ||
} | ||
|
||
/** | ||
* Gets circle container from scene. | ||
* | ||
* @returns - Circle container. | ||
*/ | ||
export function getCircleContainer(scene: Phaser.Scene) { | ||
return scene.data.get(CIRCLE_CONTAINER) as Phaser.GameObjects.Container; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Circle'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters