Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

[SOLVED] How to attach an animated sprite to another animated sprite?


msqar
 Share

Recommended Posts

I'm trying to attach some animated "dust" coming out of my main character but is not showing up on screen at all. Both are spritesheets. Here's the code:

constructor(game: Phaser.Game, x: number, y: number) {
        super(game, x, y, Assets.Spritesheets.SpritesheetsPlayer324810.getName());

        this.game = game;
        game.physics.arcade.enable(this);

        this.body.gravity.y = Player.GRAVITY;
        this.body.velocity.x = 0;
        this.body.maxVelocity = 500;

        this.cursors = this.game.input.keyboard.createCursorKeys();

        this.animations.add('running', [5, 6, 7, 8], 20, true);
        this.anchor.setTo(0.5, 0.5);

        this.runningDust = this.game.add.sprite(this.x - 10, this.y - 18, 'dust');
        this.runningDust.animations.add('move', [0, 1, 2], 10, true);
        this.runningDust.anchor.setTo(0.5, 0.5);

        this.addChild(this.runningDust);
    }

And then i just try to run the dust animations when my player runs right/left, left it basic for now:

this.runningDust.animations.play('move');

Is it possible? i assume it is, but all the tutorials i saw so far are based on plain sprites, not animated ones.

Link to comment
Share on other sites

Ohhh i saw the error, i'm sorry. Not sleeping much. Of course it won't show up if i'm setting the coordinates of player.x and player.y instead of 0,0.... for all attached children, always the coordinates needs to be 0,0 or close to that depending on the preferred offset based on parent.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...