├── .gitignore
├── .prettierignore
├── .prettierrc
├── .prettierrc.json
├── LICENSE
├── README.md
├── docs
├── _config.yml
├── generated
│ ├── .nojekyll
│ ├── assets
│ │ ├── highlight.css
│ │ ├── icons.js
│ │ ├── icons.svg
│ │ ├── main.js
│ │ ├── navigation.js
│ │ ├── search.js
│ │ └── style.css
│ ├── classes
│ │ ├── ContainerSizeCalculator.html
│ │ ├── DefaultScreenSizeCalculator.html
│ │ ├── FixedSizeCalculator.html
│ │ ├── NoResizeScreenSizeCalculator.html
│ │ ├── Scene.html
│ │ └── SceneManager.html
│ ├── hierarchy.html
│ ├── index.html
│ ├── interfaces
│ │ ├── IController.html
│ │ ├── IResizable.html
│ │ ├── IScreenSizeCalculator.html
│ │ ├── ISize.html
│ │ └── IUpdatable.html
│ ├── modules.html
│ └── variables
│ │ └── VERSION.html
└── img
│ ├── Hierarchy.png
│ └── zindex.png
├── package-lock.json
├── package.json
├── rollup.config.ts
├── src
├── _version.ts
├── core
│ ├── IController.ts
│ ├── IResizable.ts
│ ├── IScreenSizeCalculator.ts
│ ├── IUpdatable.ts
│ ├── Scene.ts
│ ├── SceneManager.ts
│ └── screen-size
│ │ ├── ContainerSizeCalculator.ts
│ │ ├── DefaultScreenSizeCalculator.ts
│ │ ├── FixedSizeCalculator.ts
│ │ └── NoResizeScreenSizeCalculator.ts
└── index.ts
├── tsconfig.json
├── tslint.json
└── version.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | /dist
3 | .vscode
4 | .user
5 | .cache
6 | .rpt2_cache
7 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | docs
3 | dist
4 | .prettierrc
5 | .prettierrc.json
6 | package-lock.json
7 | package.json
8 | README.md
9 | rollup.config.js
10 | tsconfig.json
11 | tslint.json
12 | version.js
13 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 140,
3 | "tabWidth": 4,
4 | "trailingComma": "all",
5 | "singleQuote": true
6 | }
7 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019-2024 Enriko Riba
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Scene Graph Engine for PIXI
2 |
3 | Link to [API documentation](https://enriko-riba.github.io/pixi-scenegraph/generated/index.html)
4 |
5 | ## What is pixi-scenegraph?
6 | **pixi-scenegraph** is a package providing scene management features for **PIXI v8**
7 | It allows defining scenes and switching between them e.g. MainMenuScene, GameScene, OptionsScene etc.
8 |
9 | The following image represents the object hierarchy:
10 |
11 | 
12 |
13 | **pixi-scenegraph** is written in typescript and aimed for typescript users but not limited to typescript only projects.
14 | >*.ts -> import {SceneManager} from "pixi-scenegraph";
15 |
16 | >*.js -> var sg = require("pixi-scenegraph"); let scm = new sg.SceneManager();
17 |
18 | ### What is a Scene
19 | A Scene is like a PIXI stage, a container holding all objects we want to display. Think of scenes as game state containers e.g: loading scene, menu scene, options scene, in-game scene etc.
20 |
21 | A scene **must have a unique name** and the SceneManager can reference scenes by that name:
22 |
23 | sceneManager.ActivateScene("sceneName");
24 |
25 | Only one scene at a time is active and only the active scene is rendered. A scene can have a HudOverlay which is a container object rendered over the scene. In addition a MasterHudOverlay can be attached to the SceneManager. The MasterHudOverlay is rendered over all other content.
26 |
27 | Z-Index
28 |
29 | 
30 |
31 | ### Show me a 'Hello World' example
32 | const scm = new SceneManager(renderOptions);
33 | const myScene = new MyScene();
34 | scm.AddScene(myScene);
35 | scm.ActivateScene(myScene); // or by name scm.ActivateScene('scene_name')
36 |
37 | ### How do I switch scenes?
38 | const myScene1 = new MyScene1(); // name id 'scene_1'
39 | const myScene2 = new MyScene2(); // name id 'scene_2'
40 | const menuScene = new MenuScene(); // name id 'menu'
41 | scm.AddScene(myScene1);
42 | scm.AddScene(myScene2);
43 | scm.AddScene(menuScene);
44 | scm.ActivateScene(menuScene);
45 |
46 | inside the MenuScene class:
47 |
48 | btnStart.onClick = () => this.sceneManager.ActivateScene("scene_1");
49 |
50 | ### Angular 7 based example
51 | [git repository](https://github.com/enriko-riba/scenegraph-ng)
52 |
53 | ## Documentation
54 | [API documentation](https://enriko-riba.github.io/pixi-scenegraph/generated/index.html)
55 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-architect
2 |
--------------------------------------------------------------------------------
/docs/generated/.nojekyll:
--------------------------------------------------------------------------------
1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
--------------------------------------------------------------------------------
/docs/generated/assets/highlight.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --light-hl-0: #0000FF;
3 | --dark-hl-0: #569CD6;
4 | --light-hl-1: #000000;
5 | --dark-hl-1: #D4D4D4;
6 | --light-hl-2: #0070C1;
7 | --dark-hl-2: #4FC1FF;
8 | --light-hl-3: #001080;
9 | --dark-hl-3: #9CDCFE;
10 | --light-hl-4: #795E26;
11 | --dark-hl-4: #DCDCAA;
12 | --light-code-background: #FFFFFF;
13 | --dark-code-background: #1E1E1E;
14 | }
15 |
16 | @media (prefers-color-scheme: light) { :root {
17 | --hl-0: var(--light-hl-0);
18 | --hl-1: var(--light-hl-1);
19 | --hl-2: var(--light-hl-2);
20 | --hl-3: var(--light-hl-3);
21 | --hl-4: var(--light-hl-4);
22 | --code-background: var(--light-code-background);
23 | } }
24 |
25 | @media (prefers-color-scheme: dark) { :root {
26 | --hl-0: var(--dark-hl-0);
27 | --hl-1: var(--dark-hl-1);
28 | --hl-2: var(--dark-hl-2);
29 | --hl-3: var(--dark-hl-3);
30 | --hl-4: var(--dark-hl-4);
31 | --code-background: var(--dark-code-background);
32 | } }
33 |
34 | :root[data-theme='light'] {
35 | --hl-0: var(--light-hl-0);
36 | --hl-1: var(--light-hl-1);
37 | --hl-2: var(--light-hl-2);
38 | --hl-3: var(--light-hl-3);
39 | --hl-4: var(--light-hl-4);
40 | --code-background: var(--light-code-background);
41 | }
42 |
43 | :root[data-theme='dark'] {
44 | --hl-0: var(--dark-hl-0);
45 | --hl-1: var(--dark-hl-1);
46 | --hl-2: var(--dark-hl-2);
47 | --hl-3: var(--dark-hl-3);
48 | --hl-4: var(--dark-hl-4);
49 | --code-background: var(--dark-code-background);
50 | }
51 |
52 | .hl-0 { color: var(--hl-0); }
53 | .hl-1 { color: var(--hl-1); }
54 | .hl-2 { color: var(--hl-2); }
55 | .hl-3 { color: var(--hl-3); }
56 | .hl-4 { color: var(--hl-4); }
57 | pre, code { background: var(--code-background); }
58 |
--------------------------------------------------------------------------------
/docs/generated/assets/icons.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | addIcons();
3 | function addIcons() {
4 | if (document.readyState === "loading") return document.addEventListener("DOMContentLoaded", addIcons);
5 | const svg = document.body.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg"));
6 | svg.innerHTML = `"
Calculates viewport that horizontally fits in the device and still preserves the designed aspect ratio.
2 |Returns the designed width and height with aspect ratio 1.
2 |Simply returns the available screen size without any scaling.
2 |Link to API documentation
2 |pixi-scenegraph is a package providing scene management features for PIXI v8 3 | It allows defining scenes and switching between them e.g. MainMenuScene, GameScene, OptionsScene etc.
4 |The following image represents the object hierarchy:
5 |pixi-scenegraph is written in typescript and aimed for typescript users but not limited to typescript only projects.
7 |8 |10 |*.ts -> import {SceneManager} from "pixi-scenegraph";
9 |
11 |13 |*.js -> var sg = require("pixi-scenegraph"); let scm = new sg.SceneManager();
12 |
A Scene is like a PIXI stage, a container holding all objects we want to display. Think of scenes as game state containers e.g: loading scene, menu scene, options scene, in-game scene etc.
14 |A scene must have a unique name and the SceneManager can reference scenes by that name:
15 |sceneManager.ActivateScene("sceneName");
16 |
17 | Only one scene at a time is active and only the active scene is rendered. A scene can have a HudOverlay which is a container object rendered over the scene. In addition a MasterHudOverlay can be attached to the SceneManager. The MasterHudOverlay is rendered over all other content.
18 |Z-Index
19 |const scm = new SceneManager(renderOptions);
21 | const myScene = new MyScene();
22 | scm.AddScene(myScene);
23 | scm.ActivateScene(myScene); // or by name scm.ActivateScene('scene_name')
24 |
25 | const myScene1 = new MyScene1(); // name id 'scene_1'
26 | const myScene2 = new MyScene2(); // name id 'scene_2'
27 | const menuScene = new MenuScene(); // name id 'menu'
28 | scm.AddScene(myScene1);
29 | scm.AddScene(myScene2);
30 | scm.AddScene(menuScene);
31 | scm.ActivateScene(menuScene);
32 |
33 | inside the MenuScene class:
34 |btnStart.onClick = () => this.sceneManager.ActivateScene("scene_1");
35 |
36 | Defines a controller. Controllers are non-renderable objects who's update() method is invoked once per frame. 2 | A controller can run either for all scopes or in the scope of a scene. 3 | If a scope is defined, the Controller.update() is invoked only if the ActiveScene.Name matches the scope.
4 |Readonly
idThe unique controller id.
8 |Readonly
scopeA scene name, if present activates the controller only while the scene is active. 9 | If no scope is defined the controller is active regardless of the active scene.
10 |Invoked once per frame, depending on scope.
11 |the elapsed time in milliseconds
12 |the current scene
13 |Contract for screen size and aspect ratio calculation.
2 | The SceneManager
delegates all screen size measurements to an IScreenSizeCalculator
instance.
The calculated screen size is game specific and can return any value fit for a particular game design. 4 | Two implementations are provided out of the box: the default DefaultScreenSizeCalculator and NoResizeScreenSizeCalculator. 5 | The DefaultScreenSizeCalculator calculates a viewport that horizontally fits on screen and preserves the given aspect rastio 6 | while the NoResizeScreenSizeCalculator always returns the full screen size disregarding any aspect ratio constraints.
7 |The IScreenSizeCalculator is used in resize events in the following manner:
8 |const avlSize = this.screenSizeCalculator.GetAvailableSize();
const aspect = this.screenSizeCalculator.GetAspectRatio();
const size = this.screenSizeCalculator.CalculateSize(avlSize, aspect);
this.renderer.resize(size.x, size.y);
9 |
10 |
11 | Supports onUpdate, fired on each animation frame.
2 |Const
Preserves the container width and height, no aspect ratio is calculated.
2 |