OTG Posted February 1, 2017 Share Posted February 1, 2017 Hi everyone, recent lurker, first-time poster. I'm attempting to position an HTML input element based on the world position of a phaser display object. Something very strange is occurring when I log the point to the console. The sprite's world point is returning 0, 0 but when I expand the point object in the console it's showing values other than 0, 0 (in chrome and safari the X values are the same but the Y vales are different). See attached images. Chrome: Safari: Any idea what's happening? And why the values are different in Safari and Chrome? Link to comment Share on other sites More sharing options...
drhayes Posted February 2, 2017 Share Posted February 2, 2017 Instead of logging the whole point object (e.g. "console.log(sprite.position);") try logging the values (e.g. "console.log(sprite.position.x, sprite.position.y);"). This might be an instance of the console displaying a reference to the object; when you expand it, it shows you the current value instead of the value at that time. I wouldn't worry too much about the values being different in different browsers right now. Link to comment Share on other sites More sharing options...
OTG Posted February 2, 2017 Author Share Posted February 2, 2017 Thank you for your reply. I should've mentioned in my original post that I did log the X and Y separately and got 0, 0. Link to comment Share on other sites More sharing options...
samme Posted February 2, 2017 Share Posted February 2, 2017 I think that's normal, when you expand an object you get a "snapshot" of its current values, not the values from when it was first logged. Link to comment Share on other sites More sharing options...
OTG Posted February 2, 2017 Author Share Posted February 2, 2017 I see. The issue then is that the display object's world point is returning 0,0. The display object is being added as a child to a sprite that's already been added to the world so I'm not sure why it'd be reporting back these values. Link to comment Share on other sites More sharing options...
Tom Atom Posted February 2, 2017 Share Posted February 2, 2017 Hi, any chance you are setting and reading world position in the same frame? World position will be updated after updateTransform() is called by game loop. Try to read world position in next frame. Link to comment Share on other sites More sharing options...
OTG Posted February 3, 2017 Author Share Posted February 3, 2017 @Tom Atom I'm doing exactly that! Whoops... That makes sense now but definitely wouldn't have occurred to me. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts