Jump to content

rotating sprite around another sprite , using pivot/anchor only changes the image position


Recommended Posts

I am building a pool game i want to make the cue rotate around the white ball

Here is the live code :


Here is the white balll

balls = game.add.group();balls.enableBody = true;balls.physicsBodyType = Phaser.Physics.P2JS;wball = balls.create(350, 240 , 'ballW');wball.body.setCircle(15);wball.body.setCollisionGroup(wballCollisionGroup);wball.body.collides([wballCollisionGroup, ballsCollisionGroup , sidesCollisionGroup , holesCollisionGroup , playerCollisionGroup]);game.physics.p2.setImpactEvents(true);

Hhere is the cue which i call player

player = game.add.sprite( wball.x  , 240 , 'player');game.physics.p2.enable(player , true );player.enableBody = true;player.body.setCollisionGroup(playerCollisionGroup);player.anchor.setTo(-0.5, 0.5);player.pivot.x = wball.x +150;player.pivot.y = 0;

The problem is all pivot or anchor does is change the sprite image position

I got the cue on the right place by using both pivot/anchor and it seems to work fine .. the cue was rotating around the ball but after enabling debug mode here is what i saw



Basically only position of image has been changed but he sprite still rotates at the center which is the red part

And if i run this code , ball and cue are already collide and the ball jumps around without player doing anything


how can i rotate the cue around the ball without them colliding ?

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.

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.


  • Recently Browsing   0 members

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