Closed r0m1n closed 4 years ago
Let me check 👍
It looks like you can't do that because scene property of the game instance is a SceneManager
in Phaser 3
I'm learning Phaser 3, in the meantime you can do this => https://github.com/proyecto26/ion-phaser/blob/master/demo-angular/src/app/app.component.ts#L54
I'm learning Phaser 3, in the meantime you can do this => https://github.com/proyecto26/ion-phaser/blob/master/demo-angular/src/app/app.component.ts#L54
thanks!
I'm reopening the issue because I have the same question 😅
What wrong with this.game.instance.scene.getAt(0).someMethod()? It works for me at least.
woww, really? I was debugging but maybe I didn't see because TypeScript haha
@r0m1n how are you adding that method? I have an error warning like this: ERROR TypeError: scene. someMethod is not a function
I have created new class for the scene that extends PhaserScene. Something like this:
class TestScene extends Phaser.Scene{
constructor() {
super({key: 'TestScene'});
}
preload() {....
}
someMethod(param){
}
and in the config I just passing it to the "scene" field
game = {
width: "100%",
height: "50%",
type: Phaser.AUTO,
scene: [TestScene],
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}},
instance: null
}
not exactly sure is it necessary to create a new class for the scene to make thing works, but for me it seems like more neat way to do this then just writing full scene code into the config.
Awesome and yes, you're right! <3
yeah, it's working here https://github.com/proyecto26/ion-phaser/blob/master/demo-angular/src/app/app.component.ts#L91
Hello. How could I call some function inside a scene from a component itself? Tried to do something like "this.game.instance.someMethod()" or " this.game.instance.scene.someMethod()" but it gives me error "someMethod() is not a function". full code:
`
import { Component, OnInit } from '@angular/core'; import * as Phaser from 'phaser';@Component({ selector: 'app-dancefloor', templateUrl: './dancefloor.component.html', styleUrls: ['./dancefloor.component.scss'] }) export class DancefloorComponent implements OnInit {
map = new Array(); initialize = false; game = { width: "50%", height: "50%", type: Phaser.AUTO, scene: { init: function() { this.cameras.main.setBackgroundColor('#24252A') }, create: function() { this.helloWorld = this.add.text( this.cameras.main.centerX, this.cameras.main.centerY, "Hello World", { font: "40px Arial", fill: "#ffffff" } ); this.helloWorld.setOrigin(0.5); }, update: function() { this.helloWorld.angle += 1; }, someMethod: function () { this.helloWorld.angle -= 180; } }, instance: null }
constructor(){ }
initializeGame() { this.initialize = true;
}
ngOnInit() { this.initializeGame();
}
generateNewTile(isHero:boolean = false) { return new Tile('1', isHero, this.getRandomInt(1,4)); }
getRandomInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; }
}
class Tile { type:string; isHero:boolean; score: number;
constructor(type, isHero,collectableItem){ this.type= type; this.isHero = isHero; this.score = collectableItem; }
} ``