-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
80 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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
import * as PIXI from "pixi.js"; | ||
import {IState} from "./iState"; | ||
import {StateManager} from "./stateManager"; | ||
module PixiScenes { | ||
export class BaseState extends PIXI.Container implements IState { | ||
|
||
export class BaseState extends PIXI.Container implements IState { | ||
|
||
public app: PIXI.Application|null; | ||
public states: StateManager|null; | ||
|
||
constructor() { | ||
super(); | ||
this.app = null; | ||
this.states = null; | ||
public app: PIXI.Application|null; | ||
public states: StateManager|null; | ||
|
||
constructor() { | ||
super(); | ||
this.app = null; | ||
this.states = null; | ||
} | ||
|
||
public init(): void {} | ||
public start(): void {} | ||
public stop(): void {} | ||
public update(delta: number): void {} | ||
} | ||
|
||
public init(): void {} | ||
public start(): void {} | ||
public stop(): void {} | ||
public update(delta: number): void {} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import * as PIXI from "pixi.js"; | ||
import {StateManager} from "./StateManager"; | ||
|
||
export interface IState extends PIXI.Container { | ||
app: PIXI.Application|null; | ||
states: StateManager|null; | ||
init(): void; | ||
start(): void; | ||
stop(): void; | ||
update(delta: number): void; | ||
module PixiScenes { | ||
export interface IState extends PIXI.Container { | ||
app: PIXI.Application|null; | ||
states: StateManager|null; | ||
init(): void; | ||
start(): void; | ||
stop(): void; | ||
update(delta: number): void; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export {IState} from "./iState"; | ||
export {BaseState} from "./baseState"; | ||
export {StateManager} from "./stateManager"; | ||
declare module 'pixi-scenes' { | ||
export = PixiScenes; | ||
} |
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 |
---|---|---|
@@ -1,62 +1,61 @@ | ||
import * as PIXI from "pixi.js"; | ||
import {IState} from "./iState"; | ||
|
||
export class StateManager { | ||
|
||
private app: PIXI.Application; | ||
private states: {[name: string]: IState}; | ||
private current: string|null; | ||
|
||
constructor(app: PIXI.Application) { | ||
this.app = app; | ||
this.states = {}; | ||
this.current = null; | ||
// Listen for animate update | ||
app.ticker.add(this.update.bind(this)); | ||
} | ||
|
||
private update(delta: number): void { | ||
let active: IState|null = this.active; | ||
if (active) { | ||
active.update(delta); | ||
module PixiScenes { | ||
export class StateManager { | ||
|
||
private app: PIXI.Application; | ||
private states: {[name: string]: IState}; | ||
private current: string|null; | ||
|
||
constructor(app: PIXI.Application) { | ||
this.app = app; | ||
this.states = {}; | ||
this.current = null; | ||
// Listen for animate update | ||
app.ticker.add(this.update.bind(this)); | ||
} | ||
} | ||
|
||
public add(name: string, state: IState): void { | ||
if (this.contains(name)) { | ||
return; | ||
private update(delta: number): void { | ||
let active: IState|null = this.active; | ||
if (active) { | ||
active.update(delta); | ||
} | ||
} | ||
this.states[name] = state; | ||
//state.app = this.app; | ||
//state.states = this; | ||
state.init(); | ||
} | ||
|
||
public contains(name: string): boolean { | ||
return !!this.states[name]; | ||
} | ||
|
||
public start(name: string): void { | ||
if (!this.contains(name) || name === this.current) { | ||
return; | ||
public add(name: string, state: IState): void { | ||
if (this.contains(name)) { | ||
return; | ||
} | ||
this.states[name] = state; | ||
//state.app = this.app; | ||
//state.states = this; | ||
state.init(); | ||
} | ||
|
||
// Stop current | ||
let active: IState|null = this.active; | ||
if (active) { | ||
active.stop(); | ||
this.app.stage.removeChild(active); | ||
public contains(name: string): boolean { | ||
return !!this.states[name]; | ||
} | ||
|
||
// Start new | ||
this.current = name; | ||
if (active = this.active) { | ||
this.app.stage.addChild(active); | ||
active.start(); | ||
public start(name: string): void { | ||
if (!this.contains(name) || name === this.current) { | ||
return; | ||
} | ||
|
||
// Stop current | ||
let active: IState|null = this.active; | ||
if (active) { | ||
active.stop(); | ||
this.app.stage.removeChild(active); | ||
} | ||
|
||
// Start new | ||
this.current = name; | ||
if (active = this.active) { | ||
this.app.stage.addChild(active); | ||
active.start(); | ||
} | ||
} | ||
} | ||
|
||
public get active(): IState|null { | ||
return this.current ? this.states[this.current] : null; | ||
public get active(): IState|null { | ||
return this.current ? this.states[this.current] : null; | ||
} | ||
} | ||
} |