Noaml1 Posted May 22, 2014 Share Posted May 22, 2014 i'm trying to follow the starstruck example in remake it in typescript and im getting an error i dont understand.This is what i have so far :create() { this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.stage.backgroundColor = '#000000'; this.bg = this.game.add.tileSprite(0, 0, 800, 600, 'background'); this.bg.fixedToCamera = true; this.map = this.game.add.tilemap('level1'); this.map.addTilesetImage('tiles-1'); this.map.setCollisionByExclusion([13, 14, 15, 16, 46, 47, 48, 49, 50, 51]); this.layer = this.map.createLayer('Tile Layer 1'); this.layer.resizeWorld(); this.game.physics.arcade.gravity.y = 250; this.player = this.game.add.sprite(32, 32, 'dude'); this.game.physics.enable(this.player, Phaser.Physics.ARCADE); this.player.body.bounc.y = 0.2; this.player.body.collideWorldBounds = true; this.player.body.setSize(20, 32, 5, 16); this.player.animations.add('left', [0, 1, 2, 3], 10, true); this.player.animations.add('turn', [4], 20, true); this.player.animations.add('right', [5, 6, 7, 8], 10, true); this.game.camera.follow(this.player); this.cursors = this.game.input.keyboard.createCursorKeys(); this.jumpbutton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); } update() { this.game.physics.arcade.collide(this.player, this.layer); this.player.body.velocity.x = 0; if (this.cursors.right.isDown) { this.player.body.velocity.x = 150; this.player.animations.play('right'); } }everythings been loaded correctly in the preload methodand im getting the error:Phaser v2.0.5 - Canvas - WebAudio http://phaser.io ♥♥♥ phaser.js:19908Uncaught TypeError: Cannot set property 'y' of undefined Main.ts:39Uncaught TypeError: Cannot read property 'right' of undefined Main.ts:58 the first error occurs in this area: this.game.physics.enable(this.player, Phaser.Physics.ARCADE); this.player.body.bounc.y = 0.2;the second here:this.player.body.velocity.x = 0; if (this.cursors.right.isDown) {what's happening? Link to comment Share on other sites More sharing options...
Noaml1 Posted May 22, 2014 Author Share Posted May 22, 2014 Also, when i try to run in internet explorer i get this error: Unhandled exception at line 10, column 5 in http://localhost:16322/scripts/Main.js 0x800a1391 - Microsoft JScript runtime error: 'Phaser' is undefined Link to comment Share on other sites More sharing options...
lewster32 Posted May 22, 2014 Share Posted May 22, 2014 The first error is because of a typo; it's body.bounce, not body.bounc. This may be causing the second error to occur due to script halting; though it could also be a scope issue because of 'this'. Try fixing the first error and see what happens. The IE error is a little bit weird; presumably you're loading phaser.js or phaser.min.js before Main.js? If not, Phaser will not be available when your script calls it. Link to comment Share on other sites More sharing options...
Noaml1 Posted May 22, 2014 Author Share Posted May 22, 2014 Wow that worked thanks! My game now runsthe internet explorer issue is still there though, and yea im loading phaser.js Link to comment Share on other sites More sharing options...
lewster32 Posted May 22, 2014 Share Posted May 22, 2014 I think I'd probably need to see it for myself to identify that issue, seems to me like a race condition (Phaser isn't being loaded in time for when it's used). You could try loading phaser.js in the <head> section of your page, then loading Main.js just before </body> maybe. Link to comment Share on other sites More sharing options...
Recommended Posts