titmael Posted June 18, 2014 Share Posted June 18, 2014 Hi, here is my Weapon "class" :function Weapon(game, x, y, sprite, hero){ Phaser.Sprite.call(this, game, x, y, sprite); this.anchor.setTo(.5, 1); this.game.physics.p2.enable(this, true); this.body.motionState = Phaser.Physics.P2.Body.KINEMATIC; this.using = false; this.hero = hero;}Weapon.prototype = Object.create(Phaser.Sprite.prototype);Weapon.prototype.constructor = Weapon;I don't get why when I rotate it withthis.body.angle -= 0.1;the sprite rotate from it's middle and not from (0.5, 1) anchor point ? Any ideas ? Link to comment Share on other sites More sharing options...
lewster32 Posted June 18, 2014 Share Posted June 18, 2014 Enabling P2 resets the anchor to 0.5, 0.5. Try setting your anchor after enabling physics, though I think there may be a specific reason why P2 needs it to be centered. Link to comment Share on other sites More sharing options...
titmael Posted June 18, 2014 Author Share Posted June 18, 2014 Ok maybe there is another way to redefined the anchor properly for the sprite and P2 body ? Link to comment Share on other sites More sharing options...
lewster32 Posted June 18, 2014 Share Posted June 18, 2014 Maybe add the hammer to a group and offset it in the group, then rotate the group? Link to comment Share on other sites More sharing options...
titmael Posted June 18, 2014 Author Share Posted June 18, 2014 Here is what happens when I move "this.anchor.setTo(.5, 1);" after P2 init (the debug body is hammer's) Link to comment Share on other sites More sharing options...
titmael Posted June 18, 2014 Author Share Posted June 18, 2014 Came up with this :this.game.physics.p2.enable(this, true);this.anchor.setTo(.5, 1);this.body.clearShapes();this.body.addRectangle(29, 52, 0, -26);this.body.updateCollisionMask(); Link to comment Share on other sites More sharing options...
Recommended Posts