Shadowstep33 Posted February 17, 2016 Share Posted February 17, 2016 Hi guys, I was trying to find an answer to this but had some problems (maybe my Google-fu is just a little off today). Thankfully, I figured out the answer myself. Assuming you have a character walking around in a world of containers (for example, walking from one zone to the other where each zone is a container that is next to the other) the calculation is: newX = oldX + (oldContainerX - newContainerX); newY = oldY + (oldContainerY - newContainerY); and a real code example: if(buckets['walking'].parent){ var newX = buckets['walking'].position.x + (buckets['walking'].parent.position.x - buckets.biomes[overlappingBiomes[0]].scen.position.x); var newY = buckets['walking'].position.y + (buckets['walking'].parent.position.y - buckets.biomes[overlappingBiomes[0]].scen.position.y); // buckets['walking'].parent.removeChild(buckets['walking']); buckets.biomes[overlappingBiomes[0]].scen.addChild(buckets['walking']); buckets['walking'].position.x = newX; buckets['walking'].position.y = newY; } Hopefully this helps someone! Cheers Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 17, 2016 Share Posted February 17, 2016 And when you are comparing obj1 and obj2 from different containers: let differenceX = (obj2.x - obj1.x) + (obj2.parent.x - obj1.parent.x); That helps in case of very big maps, you wont lose precision that way And I wont paste here the code for universal portal engine which i have Formulas are much more difficult there. Quote Link to comment Share on other sites More sharing options...
Shadowstep33 Posted February 17, 2016 Author Share Posted February 17, 2016 niceee thank you that will definitely come in useful for my purposes! 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.