Jump to content

[HELP] Player sprite does not appear


Todi
 Share

Recommended Posts

Hi guys,

 

I'm new here, I'm following some topics, but I can't find out one that help me. So, I'm posting it. If exist another topic, with the same doubt, sorry!
 
Well, this is my code:
 
create: function () {	this.scale.pageAlignHorizontally = true;	this.scale.pageAlignVertically = true;	// Load map	this.map = this.game.add.tilemap('level1');	this.map.addTilesetImage('brick');	this.map.addTilesetImage('door');	this.map.addTilesetImage('window');	// Load layers	this.background = this.map.createLayer('Background');	this.foreground = this.map.createLayer('Foreground');	this.background.resizeWorld();	// Create the respawn point	this.respawn = this.game.add.group();	this.map.createFromObjects('House', 4, '', 0, true, false, this.respawn);	// Set player on the map	this.respawn.forEach(function (pos) {		// Init player		this.player = this.game.add.sprite(pos.x, pos.y, 'player');		// Setup player physics		this.game.physics.enable(this.player, Phaser.Physics.ARCADE);		// Enable camera follow		this.game.camera.follow(this.player);	}, this);	// Wrapper keyboard	this.cursors = this.game.input.keyboard.createCursorKeys();},
 
I'd like to know what I have done wrong?! I just grab the respawn point from Tiled, extracted x and y positions, and I created the player instance, but, the image loaded doesn't appear in the spot. The funny thing is, I was setting the player position manually, with the exact coordinate of the respawn point and it doesn't showed up. But, when I set the player coordinate for a lower number like 32 x 32 or 100 x 100 the sprite appear normally.
 
Did you know what's going on?
 
Thank you!
Link to comment
Share on other sites

I'm new to Phaser too, so forgive me if I'm wasting your time, but have you set a breakpoint where you add your sprite to check your values for pos.x and pos.y? Also, for my sprites I had to call 

this.group.setAll('anchor.x', 0.5);this.group.setAll('anchor.y', 0.5);

so that the position referenced the center of the sprite, rather than a corner. 

 

Hope that helps.

Link to comment
Share on other sites

I'm new to Phaser too, so forgive me if I'm wasting your time, but have you set a breakpoint where you add your sprite to check your values for pos.x and pos.y? Also, for my sprites I had to call 

this.group.setAll('anchor.x', 0.5);this.group.setAll('anchor.y', 0.5);

so that the position referenced the center of the sprite, rather than a corner. 

 

Hope that helps.

 

So, I put the breakpoints and see the class Phaser.Sprite:

TypeError: Cannot read property 'x' of undefined at Object.defineProperty.get (http://localhost:8080/lib/phaser.js:14512:30) at remoteFunction (<anonymous>:3:14) at Object.InjectedScript.callFunctionOn (<anonymous>:751:66) at Object.<anonymous> (http://localhost:8080/js/level1.js:39:8) at Phaser.Group.forEach (http://localhost:8080/lib/phaser.js:34187:26) at Object.Necropole.Level1.create (http://localhost:8080/js/level1.js:34:16) at Phaser.StateManager.loadComplete (http://localhost:8080/lib/phaser.js:30867:35) at Phaser.Loader.finishedLoading (http://localhost:8080/lib/phaser.js:73782:25) at Phaser.Loader.processLoadQueue (http://localhost:8080/lib/phaser.js:73737:18) at Phaser.Loader.asyncComplete (http://localhost:8080/lib/phaser.js:73810:14)
TypeError: Cannot read property 'y' of undefined at Object.defineProperty.get (http://localhost:8080/lib/phaser.js:14530:30) at remoteFunction (<anonymous>:3:14) at Object.InjectedScript.callFunctionOn (<anonymous>:751:66) at Object.<anonymous> (http://localhost:8080/js/level1.js:39:8) at Phaser.Group.forEach (http://localhost:8080/lib/phaser.js:34187:26) at Object.Necropole.Level1.create (http://localhost:8080/js/level1.js:34:16) at Phaser.StateManager.loadComplete (http://localhost:8080/lib/phaser.js:30867:35) at Phaser.Loader.finishedLoading (http://localhost:8080/lib/phaser.js:73782:25) at Phaser.Loader.processLoadQueue (http://localhost:8080/lib/phaser.js:73737:18) at Phaser.Loader.asyncComplete (http://localhost:8080/lib/phaser.js:73810:14)

The positions X and Y of the sprite are not set. Did you know how to solve this?

 

Thanks!

 

EDIT: There is another problem. What I said before, I think it's "normal". So, now, I reset the player sprite to the visible area, and the camera don't follow him anymore.  :(

 

EDIT²: Ok... I solved it... was a CSS problem that affect the viewport of the game!  :angry: Thanks @buttonsrtoys!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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