crysfel Posted September 2, 2014 Share Posted September 2, 2014 Hi guys! Im having an issue when setting the x and y coordinates to my sprite, here's the thing: Im creating my main character in the create method as follow:me.player = new Hunter(me.game,30, me.game.world.height - 128);me.game.add.existing(me.player);me.game.camera.follow(me.player); The first time it works perfect, the hunter gets displayed in the correct coordinates, the camera is following the hunter as it moves in the world, however... after the hunter is dead I show a message to the user and a button to restart the level, when the user clicks/tab the button I execute this line of code to restart the level.this.game.state.start('play');This runs the shutdown method in my state to destroy the current elements, and then the create method is executed again, the hunter is created but instead of been displayed in x=30 and y=me.game.world.height - 128, the hunter is displayed whenever the camera is, it looks like the coordinates in the constructor of the sprite are relative to the camera and not to the world. Here's the code I have in the Hunter constructor class:var Hunter = function(game, x, y, frame) { var me = this; Phaser.Sprite.call(me, game, x, y, 'dude', frame);}Here's the link of the game, play a few times and look how the hunter is not been placed in the right coordinates. http://gorillas.aprendejs.com/ Maybe I'm doing something wrong? is there another way to set the coordinates to a sprite? I also tried this but didn't work:me.player = new Hunter(me.game,30, me.game.world.height - 128);me.player.body.x = 30;me.player.body.y = me.game.world.height - 128 //forcing coordinatesThank you so much for your help. Link to comment Share on other sites More sharing options...
Recommended Posts