# Need help with sprites

**URL:** <https://phaser.discourse.group/t/need-help-with-sprites/1221>\
**Category:** Phaser 3\
**Created:** [February 14, 2019, 5:38am UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221 "2019-02-14T05:38:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tico1711](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/tico1711/32/722_2.png) [@Tico1711](https://phaser.discourse.group/u/Tico1711)\
**Post date:** [February 14, 2019, 5:38am UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221/1 "2019-02-14T05:38:14Z")

</div>

Hello guys

I’m a begginer to Phaser and game dev in general. I am working on a project which is a sea warfare game. We start pretty basic, two boats in the sea. Here comes the challenge.

I have a boat sprite (png) and a cannon sprite (another png). The boat is physics enabled (matter). What I need to acomplish is having the cannon sprite on top of the boat (as if it were the boat’s cannon) but it has to move independently with a different set of keys (the movement will be restricted to just rotating 360 degrees for aiming). Apart from this independent rotation, the cannon has to be on top of the boat all the time, as part of it.

can this be done? and if so… how?

Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![jjcapellan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jjcapellan/32/542_2.png) [@jjcapellan](https://phaser.discourse.group/u/jjcapellan)\
**Post date:** [February 14, 2019, 4:15pm UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221/2 "2019-02-14T16:15:11Z")

</div>

Hi @Tico1711  
It would be something like this:

```javascript
function update(){
    cannon.x = boat.x + offsetX;
    cannon.y = boat.y + offsetY;

    if(yourKey.isDown){
        cannon.angle++;
    }
    // More code ...
}

```

I hope it helps you.  
Regards.

---

<div class="post-metadata">

**Author:** ![Tico1711](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/tico1711/32/722_2.png) [@Tico1711](https://phaser.discourse.group/u/Tico1711)\
**Post date:** [February 14, 2019, 4:42pm UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221/3 "2019-02-14T16:42:28Z")

</div>

Nice! I can clearly understand this code and it works like a charm!  
Another question if I may:

1. How can I fix the angle of the cannon so it is always pointing forward unless moved by the key?

---

<div class="post-metadata">

**Author:** ![rich](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rich/32/4_2.png) [@rich](https://phaser.discourse.group/u/rich)\
**Post date:** [February 14, 2019, 4:50pm UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221/4 "2019-02-14T16:50:17Z")

</div>

`cannon.setAngle(deg)` or `cannon.setRotation(rad)` if you prefer working in radians.

---

<div class="post-metadata">

**Author:** ![cinead](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/cinead/32/578_2.png) [@cinead](https://phaser.discourse.group/u/cinead)\
**Post date:** [February 14, 2019, 8:26pm UTC](https://phaser.discourse.group/t/need-help-with-sprites/1221/5 "2019-02-14T20:26:56Z")

</div>

Your game sounds cool!

Be sure to post a link back to it whenever you have completed it. I’d love to check it out.
