]>
Commit | Line | Data |
---|---|---|
1 | import { Graphics } from 'pixi.js'; | |
2 | ||
3 | /** | |
4 | * Factory object that contains many methods to create prefab pixi | |
5 | * objects | |
6 | * | |
7 | * @type object | |
8 | * @name PixiFactory | |
9 | */ | |
10 | export default { | |
11 | ||
12 | /** | |
13 | * Creates a sumo container | |
14 | * | |
15 | * @function createSumo | |
16 | * @memberof PixiFactory | |
17 | * @return {external:CreateJs.Container} the created container | |
18 | */ | |
19 | createSumo(config) { | |
20 | ||
21 | const radius = config.radius; | |
22 | ||
23 | // The body | |
24 | const body = new Graphics(); | |
25 | body.beginFill(0x87c5ea) | |
26 | .drawCircle(0, 0, radius) | |
27 | .endFill(); | |
28 | ||
29 | // The mouth | |
30 | const mouth = new Graphics(); | |
31 | mouth.lineStyle(10, 0xff0080, 1) | |
32 | .arc( | |
33 | 0, 0, // center | |
34 | radius * 0.6, | |
35 | Math.PI / 6, | |
36 | 5 * Math.PI / 6 | |
37 | ); | |
38 | ||
39 | const leftEye = new Graphics(); | |
40 | leftEye.beginFill(0xffffff) | |
41 | .drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 5) | |
42 | .endFill(); | |
43 | ||
44 | const rightEye = new Graphics(); | |
45 | rightEye.beginFill(0xffffff) | |
46 | .drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 5); | |
47 | ||
48 | const leftPupil = new Graphics(); | |
49 | leftPupil.beginFill(0x11) | |
50 | .drawCircle(-radius / 3 - radius / 8, -radius / 4, radius / 10); | |
51 | ||
52 | const rightPupil = new Graphics(); | |
53 | leftPupil.beginFill(0x11) | |
54 | .drawCircle(radius / 3 + radius / 8, -radius / 4, radius / 10); | |
55 | ||
56 | // The group | |
57 | body.addChild(mouth); | |
58 | body.addChild(leftEye); | |
59 | body.addChild(rightEye); | |
60 | body.addChild(leftPupil); | |
61 | body.addChild(rightPupil); | |
62 | ||
63 | return body; | |
64 | }, | |
65 | ||
66 | /** | |
67 | * Creates an empty graphic | |
68 | * | |
69 | * @function createEmptyGraphic | |
70 | * @memberof PixiFactory | |
71 | * @return {external:CreateJs.Container} the created container | |
72 | */ | |
73 | createEmptyGraphic(config) { | |
74 | ||
75 | return new Graphics(); | |
76 | } | |
77 | }; | |
78 |