Jump to content

Connect sprite arm to sprite body


Recommended Posts

Firstly, I am quite new to making games. I do have decent JavaScript knowledge though.

What I want is to attach a specific part of the arm sprite, onto a specific location of the body sprite. But,

I have already created a 2 independent systems for the 2 sprites:

1.  Arm Sprite Angle works!

var arm;
var player;
function create () {
        arm = this.add.sprite(player.x, player.y, 'arm').setOrigin(0, 0.5);
function update () {
    if (cursors.up.isDown) {
        arm.angle += -0.5;
    if (cursors.down.isDown) {
        arm.angle += 0.5;

2. Body Sprite Movement Works!

function create () {
     player = this.physics.add.sprite(400, 315, 'dude');
//player is body

I am not going to bother pasting the code for the player movement because it is quite long. Basically, it is controlled by setting velocity. It can move up and down & left and right.

The above code works fine, what I want to do is set the location of the arm to always be in the appropriate spot on the body, even when the body is moving. Then I also want the arm to be able to move up and down as in the code above (point 1.)

When I was first doing research on a solution, I found that Phaser 3 doesn't have a parent / child system for attaching things. Instead it has a container system. I'm not entirely sure how containers work. Can I make the body into a container, and then have the body able to be affected by the world and also able to move around, and then also have the arm rotate independently from the rotation of the container?

Another Question, how do you guys learn Phaser 3? I am struggling to find documentation. Currently I am looking at examples at https://labs.phaser.io/ and then trying to apply them to my own work.


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...