Jump to content

After state change, sprite positioning is stuck.


Recommended Posts

After moving on to a new level (changing states), my new sprite on the new level state is not being placed in the position I specify. If I give it an x position above 920, the sprite is placed at the specified x position. Below 920, the sprite is placed at 920.
My feeling is that it relates to the position of the sprite in the old state when the new state is begun, but I have been troubleshooting for a long time and have made no headway.


-Inside the first state the world bounds and player sprite position are set.

this.world.setBounds(0, 0, 1920, 1072);this.player = new Player(this.game, 32, 0);

-This function is called when the level is over and changes to the specified state named state_name.

function main_enter(obj, state_name) {    if (obj.game.paused) {        obj.game.paused = false;        obj.menu.visible = false;                obj.state.start('StartMenu');    }    if (main_checkOverlap(obj.player, obj.door) && obj.enterKey.isDown) {                obj.state.start(state_name);    }}  

-Inside the second state the world bounds and player sprite position are set.

this.world.setBounds(0, 0, 3840, 1072);this.player = new Player(this.game, 1000, 0);

-The player sprite is created by extending the sprite object.

Player = function (game, x, y) {    Phaser.Sprite.call(this, game, x, y, 'hero');    game.physics.enable(this); 	this.body.collideWorldBounds = true; 	this.body.bounce.y = 0.2; 	this.body.gravity.y = 800;    game.camera.follow(this); 	this.scale.setTo(1.5, 1.5); 	this.animations.add('left', [74, 75, 76, 77, 78], 10, true);    this.animations.add('right', [24, 25, 26, 25], 10, true);    game.add.existing(this);};Player.prototype = Object.create(Phaser.Sprite.prototype);Player.prototype.constructor = Player;

This only occurs when changing level states. If I directly move from the main menu state to any level state, the positioning is correct.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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