Daniel Belohlavek Posted April 21, 2014 Share Posted April 21, 2014 I'm using VS Express 2013 for the Web and following this tutorial: http://www.photonstorm.com/phaser/advanced-phaser-and-typescript-projects My code: Game.ts///<reference path="phaser.d.ts"/>module Crazytopia { export class Game extends Phaser.Game { constructor() { super(1023, 630, Phaser.AUTO, 'content', null); this.state.add('Boot', Boot, false); this.state.add('Preloader', Preloader, false); this.state.add('Menu', Menu, false); this.state.add('Room_1', Room_1, false); this.state.start('Boot'); } }} Boot.ts module Crazytopia { export class Boot extends Phaser.State { preload() { this.load.image('preloadBar','img/loader.png'); } create() { this.input.maxPointers = 1; this.stage.disableVisibilityChange = true; if (this.game.device.desktop) { // If you have any desktop specific settings, they can go in here [b][color=#ff0000]this.stage.scale.pageAlignHorizontally = true;[/color][/b] } this.game.state.start('Preloader', true, false); } }} Menu.tsmodule Crazytopia { export class Menu extends Phaser.State { username: Phaser.Text; menuTitle: Phaser.Text; create() { //this.stage.setBackgroundColor(0x2d2d2d); this.menuTitle = this.add.text(this.world.centerX, this.world.centerY, 'Enter your name:', { font: "30px Arial", fill: "#ffffff", align: "center" }); this.menuTitle.anchor.setTo(0.5, 0.5); this.username = this.add.text(this.world.centerX, this.world.centerY + 70, '', { font: "30px Arial", fill: "#ffffff", align: "center" }); this.username.anchor.setTo(0.5, 0.5); this.input.keyboard.addCallbacks(this, this.keyboardHandler); if (this.input.keyboard.addKey(Phaser.Keyboard.P).justPressed()) { this.startGame; } } keyboardHandler( evt ) { // Skip it unless it's a-z. if (evt.which < "A".charCodeAt(0) || evt.which > "Z".charCodeAt(0)) { console.log("Not a letter: ", evt.which); return; } var letter = String.fromCharCode(evt.which); if (!evt.shiftKey) letter = letter.toLowerCase(); this.username.setText(this.username.text + letter); } startGame() { this.game.state.start('Room_1', true, false); } }} Note: there is also Preloader.ts, Room_1.ts and app.ts but I do not think they are relevant to the problem (please correct me if I'm wrong). The errors I get:Error 1 The property 'setTo' does not exist on value of type 'PIXI.Point' (Menu.ts ln 17)this.menuTitle.anchor.setTo(0.5, 0.5);Error 2 The property 'setTo' does not exist on value of type 'PIXI.Point' (Menu.ts ln 25)this.username.anchor.setTo(0.5, 0.5);Error 3 The property 'pageAlignHorizontally' does not exist on value of type 'PIXI.Point' (Boot.ts ln 14)this.stage.scale.pageAlignHorizontally = true;I'm new to Typescript and Phaser so I have no idea what I'm doing wrong. Thanks for reading! Link to comment Share on other sites More sharing options...
rich Posted April 21, 2014 Share Posted April 21, 2014 Which version of Phaser are you using? This: this.stage.scale.pageAlignHorizontally = true; Should be: this.scale If you're using the old method above then are you maybe following an out-dated tutorial? Link to comment Share on other sites More sharing options...
Daniel Belohlavek Posted April 22, 2014 Author Share Posted April 22, 2014 Your tutorial: http://www.photonstorm.com/phaser/advanced-phaser-and-typescript-projects is from December 2013! I'm using Phaser 2.0.3 I commented out the problematic lines in Menu.ts and corrected the "pageAlignHorizontally" error (that means that anchor.setTo() still shows errors).Whenever I build and run the code I can see the loader bar fading out but the text does not appear as expected (and instructed) in Menu.ts, maybe I'm going about it the wrong way? I tried translating some vanilla JS to Typescript and again, it's my first time doing so Thanks for taking the time to answer! Link to comment Share on other sites More sharing options...
Daniel Belohlavek Posted April 22, 2014 Author Share Posted April 22, 2014 Any ideas on what the problem may be? (Sorry for the indirect bump ) Link to comment Share on other sites More sharing options...
Recommended Posts