Jump to content

Scale sprites in a group depending on their translation?


wipster
 Share

Recommended Posts

Hi,

I want to visualize the "projectiles" of a flamethrower using a group of sprites. They are moved by body physics of type arcade.

Now I'd like to scale the single projectiles up, depending on their position on the x axis or alternatively on their livetime.

How would you achieve this without draining the cpu too much? Would you use forEachAlive or some sort of callback? Might it be easier to implement using particles and can I check for collision with particles?

What I have so far:

execute() {
    let sprite = this.spriteGroup.getFirstExists(false);
    if (sprite) {
        sprite.reset(this._enemy.attackSpawnX, this._enemy.attackSpawnY);
        sprite.body.velocity.x = -200;

        setTimeout(this.execute.bind(this), 100);
    }
}

I use setTimeout in order to spawn the projectiles asynchonous until the group is empty.

greetings

Link to comment
Share on other sites

Thank your very much @samid737 I implemented it using a particle emitter. Now I wonder how I can get notified about collisions without actually let the player collide with the flames.

I check for the collision like this currently on every update:

this.game.physics.arcade.collide(this.currentAttack.emitter, this.player.sprite, this.onPlayerHit, null, this);

In order to not move the player when colliding with the flames I did this:

this.game.physics.arcade.enableBody(this._sprite);
this._sprite.body.immovable  = true;

Now the flames bounce of the player, but I only want to let them pass through it and get the callback triggered.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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