Fredrik Posted June 22, 2018 Share Posted June 22, 2018 How can I get the absolute position of a Sprite or Image in the world? I have a Sprite that is inside a container with scrollFactor of 0 and I want to move other sprites outside the container to that position. Basically this question but for Phaser 3 =) - http://www.html5gamedevs.com/topic/5306-absolute-position-of-sprite/ Link to comment Share on other sites More sharing options...
prob Posted June 22, 2018 Share Posted June 22, 2018 You could calculate it using the container position (sprite.parentContainer.x/y). Link to comment Share on other sites More sharing options...
Fredrik Posted June 22, 2018 Author Share Posted June 22, 2018 I can use the container.x & .y but it doesn't really work in my case. The container is drawn with scrollFactor 0, so when the camera moves the container does not move relative to the camera, but it does relative to the world. Thus the real world coordinates changes when the camera moves but the x & y fields in the container does not seem to update with the camera (they are what they were set to originally). Example: Initially the container is placed at 0,0. Then the player and camera scrolls 200px to the right. Now the real world position of the container is 200,0 but .x,.y still says 0,0. Hope that makes sense! ? Link to comment Share on other sites More sharing options...
jdotr Posted June 22, 2018 Share Posted June 22, 2018 I don't know if these are the _right_ answers but the two things that come to mind: 1. Manually compute the world position by taking objects in scrollFactor(0) position and adding in .scrollX and .scrollY 2. If you have access to the camera for the scene you want to position things in you can use getWorldPoint. Both approaches should let you move between screen and world positioning. samme 1 Link to comment Share on other sites More sharing options...
Fredrik Posted June 22, 2018 Author Share Posted June 22, 2018 I am playing around with this.scene.cameras.main.scrollX now, it seems to give me the current scroll offset relative to the world and from that I can add the container position etc. So I think this will work. I tried getWorldPoint as well and it gives me the same result (for camera position). It would be nice with some more intuitive way of doing it though ? Link to comment Share on other sites More sharing options...
heronww Posted August 20, 2019 Share Posted August 20, 2019 I'm not sure if it's just me but it seems objects arbitrarily mix themselves with whether or not their ".x" will use local or world coords. Without an easy way to convert between the two even the simplest operations in phaser3 seem counter-intuitive. Or could someone kindly explain what I'm doing wrong? Link to comment Share on other sites More sharing options...
stupot Posted October 2, 2019 Share Posted October 2, 2019 This example helped me: http://labs.phaser.io/view.html?src=src\game objects\container\parent matrix.js dranitski 1 Link to comment Share on other sites More sharing options...
Recommended Posts