Search the Community
Showing results for tags 'calculate'.
-
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
-
Hi! I want to import an object layer from Tiled map editor into a physics engine ( p2.js ). My problem is that p2.js uses 0.5,0.5 as anchor points, but tiled uses 0,0 (top-left). How can i recalculate it's position so i can give it the proper coordinated for a different anchor point? Any help is very much appreciated! Edit : This is easy with rectangles, but my problem is with rotated polygons.