Add touch support to companion selection scene

This commit is contained in:
PizZaKatZe 2021-04-13 00:44:51 +02:00
parent edd4e9e95d
commit e75fb9a6a9

View File

@ -29,6 +29,8 @@ export class SelectCompanionScene extends ResizableScene {
private companions: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>(); private companions: Array<Phaser.Physics.Arcade.Sprite> = new Array<Phaser.Physics.Arcade.Sprite>();
private companionModels: Array<CompanionResourceDescriptionInterface|null> = [null]; private companionModels: Array<CompanionResourceDescriptionInterface|null> = [null];
private confirmTouchArea!: Rectangle;
constructor() { constructor() {
super({ super({
key: SelectCompanionSceneName key: SelectCompanionSceneName
@ -54,12 +56,17 @@ export class SelectCompanionScene extends ResizableScene {
create() { create() {
this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Select your companion'); this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Select your companion');
const confirmTouchAreaY = 115 + 32 * Math.ceil(this.companionModels.length / this.nbCharactersPerRow);
this.pressReturnField = new TextField( this.pressReturnField = new TextField(
this, this,
this.game.renderer.width / 2, this.game.renderer.width / 2,
90 + 32 * Math.ceil(this.companionModels.length / this.nbCharactersPerRow), confirmTouchAreaY,
'Press enter to start' 'Touch here\n\n or \n\n press enter to start'
); );
this.confirmTouchArea = this.add
.rectangle(this.game.renderer.width / 2, confirmTouchAreaY, 200, 50)
.setInteractive()
.on("pointerdown", this.nextScene.bind(this));
const rectangleXStart = this.game.renderer.width / 2 - (this.nbCharactersPerRow / 2) * 32 + 16; const rectangleXStart = this.game.renderer.width / 2 - (this.nbCharactersPerRow / 2) * 32 + 16;
this.selectedRectangle = this.add.rectangle(rectangleXStart, 90, 32, 32).setStrokeStyle(2, 0xFFFFFF); this.selectedRectangle = this.add.rectangle(rectangleXStart, 90, 32, 32).setStrokeStyle(2, 0xFFFFFF);