Zenryo Posted May 31, 2014 Share Posted May 31, 2014 Hello!Can someone tell me why is this happenening?Code: http://pastebin.com/cvH6pFRiAs you can see the visual body is in a different place as the physical body. Thanks for the answers! Link to comment Share on other sites More sharing options...
lewster32 Posted May 31, 2014 Share Posted May 31, 2014 I believe there's currently an issue with pivots in pixi.js (Phaser's underlying rendering engine) that is causing problems with the position of the body. I had a similar issue and had to abandon rotation of the sprite, instead resorting to extending the sprite and rotating a child image instead. Link to comment Share on other sites More sharing options...
Zenryo Posted June 1, 2014 Author Share Posted June 1, 2014 Thanks for the answer! Can you please tell how did you do it? Link to comment Share on other sites More sharing options...
lewster32 Posted June 1, 2014 Share Posted June 1, 2014 To be fair my solution wouldn't be the right solution in your case, as presumably you need an orbiting mechanic and the ability to detect collisions on that orbiting item. In your case I may do something like this:// Create our solar system groupvar solarSystem = game.add.group();// Create our sun and use the group's 0, 0 position as the center of the solar systemvar sun = game.add.sprite(0, 0, 'sun', 0, solarSystem);// Set the sun's anchor to 0.5, 0.5 so it is completely centeredsun.anchor.set(0.5);// Create a group to manage the orbit of our planet, and place it inside the solar systemvar planet1Orbit = game.add.group(solarSystem);// Create our planet and place it off-centre by 50 pixelsvar planet1 = game.add.sprite(50, 0, 'planet', 0, planet1Orbit);// Also set the planet's anchor to 0.5 so we don't get any weird offsetsplanet1.anchor.set(0.5);// Finally add a body to the planet so we can detect collisionsgame.physics.enable(planet1, Phaser.Physics.ARCADE);// And now the magic part - rotate the planet1Orbit group instead of the planetfunction update() { planet1Orbit.angle += 1; // you can also make the planet spin separately planet1.angle += 2; // or you could make it spin in the opposite direction at the same rate, and the planet will appear to move around the sun without rotating itself // planet.angle -= 1;}This is a very simple way to get an orbit-like mechanic just by using groups. Because the scene graph allows objects to be placed inside other objects and inherit their transforms, you end up with the same effect. It does however have limitations - you will only be able to create circular orbits with this method; if you want to create more advanced orbits you'll have to do it with carefully balanced physics and maths. Zenryo 1 Link to comment Share on other sites More sharing options...
Zenryo Posted June 1, 2014 Author Share Posted June 1, 2014 Thank you for the answer, it works that way! lewster32 1 Link to comment Share on other sites More sharing options...
lewster32 Posted June 1, 2014 Share Posted June 1, 2014 Hopefully pivot will be fixed soon and you won't have to do it this way; however one of the quite a nice side effects of doing it this way is you could technically add more orbiting moons to any of the planets by recursively applying this technique, and get quite complex orrery-style systems going. Zenryo 1 Link to comment Share on other sites More sharing options...
Recommended Posts