14.3 C
New York
Thursday, October 9, 2025

rotation – Find out how to make well being bar or speech comply with however not rotate with character container?


I’ve a top-down character object that could be a Container of varied components.
This character can have components that ought to transfer together with it (assume a well being bar, a speech bubble) that ought to NOT rotate when the character rotates.

If I add it to the Container, it rotates by default.
If I do not add it to the Container, the ingredient must be moved individually to maintain up.

Neither of these work tremendous nicely for me.
Is there a neat option to flag that a part of a Container shouldn’t rotate with it?
Or that one object ought to stick to a different with out having them be in a Container? 🤔

I’ve added a practical snippet under.
My aim is to have the power to rotate the character container WITHOUT rotating the textual content area whereas nonetheless having the textual content area comply with my character when it strikes.

class DemoScene extends Phaser.Scene {
    create () {
      this.character = new Phaser.GameObjects.Container(this, 100, 100);
      this.character.add(this.add.circle(0, 0, 35, 0x00ff00));
      this.character.add(this.add.rectangle(0, 20, 40, 40, 0x009900)
            .setAngle(45));
      this.character.add(this.add.textual content(40, -20, 'Hello there!'));
      this.add.current(this.character);
      
      this.tweens.add({
        targets: this.character,
        x: 400,
        angle: 180,
        repeat: -1,
        length: 3000,
        yoyo: 1
      });
    }
}

var config = {
    width: 540,
    top: 180,
    scene: DemoScene,
}; 

new Phaser.Recreation(config);

console.clear();
doc.physique.fashion="margin:0;";

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles