Maks Posted June 17, 2015 Share Posted June 17, 2015 Hi everyone, I'm currently making a game with Phaser, and I ran into a problem. Basically I've got a player on top-down view, that can shoot bullets to a target. I'm using something like in this tutorial : https://phaser.io/tutorials/coding-tips-007 (create a shoot'em up) to fire a bullet, with a BulletPool, a SingleBullet and a fire() method : this.getFirstExists(false).fire(sprite.x, sprite.y, sprite.rotation, BulletPool.BULLET_SPEED);My sprite got an anchor set at (0.5, 0.5) and rotates according to the pointer position. Imagine, if I want to fire from gun position, when angle=0, it could be :this.getFirstExists(false).fire(sprite.x - sprite.width / 2 + 30, sprite.y - sprite.height / 2, sprite.rotation, BulletPool.BULLET_SPEED);But when I'm rotating the sprite, the gun position changes and its position is no longer "sprite.x - sprite.width / 2 + 30" Any idea to fix this one ? Link to comment Share on other sites More sharing options...
charlie_says Posted June 17, 2015 Share Posted June 17, 2015 This should do it:var myPoint = new Phaser.Point( sprite.width / 2 + 30, -sprite.height / 2);myPoint.rotate(sprite.rotation);this.getFirstExists(false).fire(sprite.x+myPoint.x, sprite.y+myPoint.y, sprite.rotation, BulletPool.BULLET_SPEED); ForgeableSum 1 Link to comment Share on other sites More sharing options...
Maks Posted June 17, 2015 Author Share Posted June 17, 2015 Yes, finally got it with Phaser.Point.rotate public fire(sprite: Phaser.Sprite, speed): void { var point = new Phaser.Point(sprite.x - sprite.width / 2 + 72, sprite.y - sprite.height / 2 - this.height); point.rotate(sprite.x, sprite.y, sprite.rotation); this.reset(point.x, point.y); this.rotation = this.body.rotation = sprite.rotation; this.body.moveForward(speed); } Thanks ! Link to comment Share on other sites More sharing options...
Tilde Posted June 18, 2015 Share Posted June 18, 2015 This awesome tutorial's been helping me a lot for stuff like this: http://jsbin.com/watipexuca/1/edit?js,output EDIT: Actually, I may not have used this for rotation code, since the ship here doesn't rotate. Whoops! :v My bad. Link to comment Share on other sites More sharing options...
Recommended Posts