Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Player class not being added in


Recommended Posts

Hi there,

Previously I had my player being created inside of the level state, but now I'm working on separating the player into its own object which I can create an instance of in the play state.

Here's my two files:


Player = function(game, x, y) {
	Phaser.Sprite.call(this, game, x, y, 'player');
	this.anchor.setTo(0.5, 0.5);

Player.prototype = Object.create(Phaser.Sprite.prototype);
Player.prototype.constructor = Player;

Player.prototype.update = function() {



Player.prototype.handleInput = function() {
	if(keys.D.isDown) this.body.velocity.x += 1;
	if(keys.A.isDown) this.body.velocity.x -= 1;
	if(this.body.onFloor() && keys.SPACE.isDown) this.body.velocity.y -= 4;


var playState = {

	create: function() {

		game.stage.backgroundColor = "#1e1e1e";
		game.physics.arcade.gravity.y = 400;

		map = game.add.tilemap('map1');
		map.addTilesetImage('moontileset', 'tileset');
		layer = map.createLayer('Tile Layer 1');
		map.setCollisionBetween(1, 16);
		player = new Player(game, 128, 96);

		game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1);


	update: function() {

		game.physics.arcade.collide(player, layer);





When I run the game, I get no errors, but the player isn't appearing on screen. Everything else works fine. The methods inside player are being called, everything. I don't know what I've done wrong.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...