WebDevUa

Uncaught TypeError in my first app.

Recommended Posts

Hello everybody

I write my first application, add physics for my player, add cursors , input keyboards. 
En error you will see on the screenshots.screenshot_768.jpg.0b56a1ec855245d9a8b68cbdd2790821.jpgscreenshot_769.jpg.171b028d40373e5e028f97ff1dded5f0.jpg

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'gameDiv');

var spacefield;

var backgroundv;

var player;

var cursors;

var mainState = {
	preload: function(){
		game.load.image('starfield', "assets/starfield.png");
		game.load.image('player', "assets/player.png");
	},

	create: function(){
		spacefield = game.add.tileSprite(0, 0, 800, 600, 'starfield');
		backgroundv = 5;

		game.add.sprite(game.world.centerX, game.world.centerY + 200, 'player');
		game.physics.enable(player, Phaser.Physics.ARCADE);

		cursors = game.input.keyboard.createCursorKeys();
	},

	update: function(){
		spacefield.tilePosition.y += backgroundv;

		if(cursors.left.isDown){
			player.body.velocity.x = -350;
		}
		if(cursors.right.isDown){
			player.body.velocity.x = 350;
		}
	}
};

game.state.add('mainState', mainState);

game.state.start('mainState');

 

Whats wrong? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.