#質問内容
クラスを跨いでcontainerをdestroyしようとしてもdestroyしてくれません。
destroySceneのalphaは正常に動作するので渡している変数は間違っていないと思うのですが...
何故動作しないのか、それとも別に問題があるのか、ご指導下さい。
#コード
index
1import Manager from './manager'; 2 3window.onload = () => { 4 Manager.start({ 5 width: 1136, 6 height: 640, 7 option: 0x222222 8 }); 9}
manager
1import * as PIXI from 'pixi.js'; 2import Scene from './scene'; 3import Scene1 from './scene1'; 4 5export default class Manager { 6 public static game: PIXI.Application; 7 public static scene: Scene; 8 9 public static start(options: { 10 width: number, 11 height: number, 12 option: number 13 }): void { 14 this.game = new PIXI.Application({ 15 width: options.width, 16 height: options.height, 17 backgroundColor: options.option 18 }); 19 document.body.appendChild(this.game.view); 20 new Scene1(this.scene); 21 } 22}
scene
1import * as PIXI from 'pixi.js'; 2import Manager from './manager'; 3 4export default class Scene { 5 public container: PIXI.Container; 6 public texture: PIXI.Texture[]; 7 public sprite: PIXI.Sprite[] = []; 8 9 constructor(texture: PIXI.Texture[]) { 10 this.container = new PIXI.Container(); 11 this.texture = texture; 12 } 13 14 public static appendScene(scene: Scene) { 15 Manager.game.stage.addChild(scene.container); 16 for (let i = 0; i < scene.texture.length; i++) { 17 scene.sprite[i] = new PIXI.Sprite(scene.texture[i]); 18 scene.container.addChild(scene.sprite[i]); 19 } 20 } 21 22 public static destroyScene(scene: Scene) { 23 Manager.game.ticker.add(() => { 24 scene.container.alpha -= 0.025; 25 if (scene.container.alpha <= 0) { 26 scene.container.destroy(); 27 Manager.game.ticker.stop(); 28 }; 29 }); 30 return true; 31 } 32}
scene1
1import * as PIXI from 'pixi.js'; 2import Scene from './scene'; 3import Manager from './manager'; 4import Scene2 from './scene2'; 5 6export default class Scene1 { 7 constructor(scene: Scene) { 8 scene = new Scene([ 9 PIXI.Texture.from('./assets/animalface_kangaroo.png'), 10 PIXI.Texture.from('./assets/animalface_kirin.png') 11 ] 12 ); 13 Scene.appendScene(scene); 14 15 scene.sprite[1].x = 250; 16 scene.sprite[1].interactive = true; 17 scene.sprite[1].buttonMode = true; 18 19 scene.sprite[1].on('pointerdown', () => { 20 if(Scene.destroyScene(scene)) { setTimeout(() => { new Scene2(Manager.scene); }, 600); }; 21 }); 22 } 23}
scene2
1import * as PIXI from 'pixi.js'; 2import Scene from './scene'; 3import Manager from './manager'; 4import Scene1 from './scene1'; 5 6export default class Scene2 { 7 constructor(scene: Scene) { 8 scene = new Scene([ 9 PIXI.Texture.from('./assets/animalface_tanuki.png'), 10 PIXI.Texture.from('./assets/animalface_usagi.png') 11 ] 12 ); 13 Scene.appendScene(scene); 14 15 scene.sprite[1].x = 250; 16 scene.sprite[1].interactive = true; 17 scene.sprite[1].buttonMode = true; 18 19 scene.sprite[1].on('pointerdown', () => { 20 if(Scene.destroyScene(scene)) { setTimeout(() => { new Scene1(Manager.scene); }, 600); }; 21 }); 22 } 23}
#環境
package
1 "devDependencies": { 2 "@types/pixi.js": "^5.0.0", 3 "ts-loader": "^8.0.3", 4 "tslint": "^6.1.3", 5 "tslint-config-airbnb": "^5.11.2", 6 "typedoc": "^0.19.0", 7 "typescript": "^4.0.2", 8 "webpack": "^4.44.1", 9 "webpack-cli": "^3.3.12", 10 "webpack-dev-server": "^3.11.0" 11 }, 12 "dependencies": { 13 "pixi.js": "^5.3.3" 14 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。