Ninjadoodle Posted June 30, 2018 Share Posted June 30, 2018 Hi @enpu I'm still working on my tiles inside container level. I've manged to get the interactivity and masks working, but now I have one more issue. I'm moving a container around with a bunch of tiles in it. When I click a tile, I would like to add it to the parent container, at the same position it is currently visible on screen. The problem is that it is adding it at the co-ordinates of the container it was inside originally. Is there any local to global function, to make this easier? Thank you in advance for any tips Quote Link to comment Share on other sites More sharing options...
enpu Posted July 3, 2018 Share Posted July 3, 2018 @Ninjadoodle You can you toWorldPosition function to do that: https://www.panda2.io/examples#container-toWorldPosition Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2018 Author Share Posted July 3, 2018 @enpu Thanks heaps, that's what I was looking for! My logic is however wrong again, so I have to see how to get it to work Quote Link to comment Share on other sites More sharing options...
enpu Posted July 3, 2018 Share Posted July 3, 2018 If you are moving your sprite from container to another (and both's world position is other than 0,0), you might need to convert your sprite position first to world position, then change it's parent and then convert it back to local position. sprite.toWorldPosition(sprite.position); // Convert to world position sprite.addTo(container); // Change parent sprite.toWorldPosition(sprite.position, true); // Convert to local position Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2018 Author Share Posted July 3, 2018 Hi @enpu Ok I see, that almost works but it's still seems to be off by some pixels - maybe because I'm centering my container. I can easily work out how much it's off by, but I don't really understand why. Thanks again for the tips! Quote Link to comment Share on other sites More sharing options...
enpu Posted July 3, 2018 Share Posted July 3, 2018 By "centering my container" you mean you have changed it's anchor? Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2018 Author Share Posted July 3, 2018 @enpu I have a 768x768 sprite ('baseBoard') and it's anchor is in the center. I've placed some more 'baseBoard' sprites inside the main sprite to extend the board to the left and right. The offset is exactly half of 768x768, so it looks like I should be keeping the anchor top left if I want to avoid it. I pretty sure this is the reason, my logic on this was just a little flawed - thanks heaps for the help! Quote Link to comment Share on other sites More sharing options...
enpu Posted July 3, 2018 Share Posted July 3, 2018 Actually it seems that the toWorldPosition was not working properly if the sprite's anchor was set other than 0,0. Can you update your engine and try again? Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2018 Author Share Posted July 3, 2018 Hi @enpu I did notice something different, the sprite moved into the new container is in a slightly diff position. I however still need to use the offset to make it work (I'm pretty sure this is my fault), but it's the same offset as before, which is strange. Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 3, 2018 Author Share Posted July 3, 2018 @enpu Actually, the offset has now doubled - which also makes sense to me Quote Link to comment Share on other sites More sharing options...
enpu Posted July 3, 2018 Share Posted July 3, 2018 @Ninjadoodle I tried different test cases and all seems to be working as expected with toWorldPosition function. If you could give me a test case, where i can clearly see the unexpected behaviour, that would help a lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.