Nexios Posted March 18, 2017 Share Posted March 18, 2017 So i am trying to orbit a small sphere around a bigger sphere like so: var orbit = new Sprite(loader.resources.RedB.texture); stage.addChild(orbit); orbit.anchor.set(0.1, 0.1); orbit.position.x= Gball.x*1.3; orbit.position.y = Gball.y/3; orbit.scale.set(0.15, 0.15); Gball.addChild(orbit); animate(); function animate() { requestAnimationFrame(animate); // just for fun, let's rotate mr Honeypot a little Gball.rotation -= 0.05; // render the container renderer.render(stage); } now the only problem is that when i click on the button to remove the child, but want him to keep the position he had in the animation: var ballX = orbit.x; var ballY = orbit.y; document.getElementById("bot").addEventListener("click", function () { var orbit = new Sprite(loader.resources.RedB.texture); stage.addChild(orbit); orbit.anchor.set(0.1, 0.1); orbit.position.x= ballX; orbit.position.y = ballY; orbit.scale.set(0.15, 0.15); Gball.removeChild(orbit); return false; }); does anyone know how i might be able to do that? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 18, 2017 Share Posted March 18, 2017 stage.addChild(orbit); Gball.addChild(orbit); Whos whos child is? I think you have to look at "Gball.toLocal(stage)" for global coords. Or something like that. Quote Link to comment Share on other sites More sharing options...
Nexios Posted March 18, 2017 Author Share Posted March 18, 2017 ok i have done something else now: var orbit = new Sprite(loader.resources.RedB.texture); stage.addChild(orbit); orbit.anchor.set(0.5,0.5); var orbitLocation = orbit.origin; orbit.pivot.set(Gball.width*25,Gball.height*25); orbit.position.set(widthHalf, heightBotb); console.log(heightBotOrbit); console.log(heightBotb); orbit.scale.set(0.02, 0.02); animate(); function animate() { requestAnimationFrame(animate); // just for fun, let's rotate mr Honeypot a little orbit.rotation -= 0.01; console.log(orbitLocation); // render the container renderer.render(stage); } and now i am trying to figure out how to get the sprites position while it is rotating around the pivot. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 18, 2017 Share Posted March 18, 2017 http://pixijs.download/dev/docs/PIXI.DisplayObject.html , look for toLocal and toGlobal. First param is just a point like "new PIXI.Point(0,0)" , second is object that you need coordinates related to (stage) Quote Link to comment Share on other sites More sharing options...
Nexios Posted March 18, 2017 Author Share Posted March 18, 2017 Thank you so much will keep you updated if i make it 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.