Zekko Posted January 8, 2015 Share Posted January 8, 2015 Hi all, long time lurker, love the framework! The fact that I've done two weeks of coding without having to ask a question really shows the quality of Phaser, the docs, and the wealth of information on the forums! Unfortunately, I couldn't find an answer to this. I'm trying to get a local point on a P2JS body converted to world co-ordinates. To put it into context: I want another sprite to move to a specific point on a physics body. Funny enough, there are parameters in the physics.p2.createSpring() that allow you to specify local points on the bodies to attach the spring to. Similar parameters are found in the P2JS constraint cosntructors. However, looking at the source code taught me nothing because it's just a reference to the P2JS spring creator. I looked in the P2JS docs to find a LinearSpring.getWorldAnchorA() function, but calling it as spring.data.getWorldAnchorA() results in the following error: Uncaught TypeError: Cannot set property '0' of undefined Phaser.js:79022 I suppose I could put the body in a group along with an invisible sprite to mark the local point and get sprite.world, but that feels so hacky. I'd create an empty group to mark the point, but groups don't have a world attribute. I could found no function in the Phaser docs to convert a local point to a world point, which seems such a simple and common thing to do. Am I missing something? Link to comment Share on other sites More sharing options...
Dennis Posted January 9, 2015 Share Posted January 9, 2015 I had the problem few days ago, took me some time to figure it out. This works for me,var localPt = new PIXI.Point(20, 40);var worldPt = this.game.world.toLocal(localPt, this.backgroundLayer); Link to comment Share on other sites More sharing options...
Zekko Posted January 9, 2015 Author Share Posted January 9, 2015 Ah, it's in the world class! I'll try it as soon as I get home. UPDATE: Works like a charm, thanks! Link to comment Share on other sites More sharing options...
bali33 Posted March 4, 2015 Share Posted March 4, 2015 Hi, I'm sorry to bump this post but I'm trying to understand the toLocal method - in the above example does that means worldPt in the game.world is the same as localPt in backgroundLayer ? Thx. Link to comment Share on other sites More sharing options...
Recommended Posts