Jump to content

Nexios
 Share

Recommended Posts

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...