wipster Posted November 21, 2017 Share Posted November 21, 2017 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 More sharing options...
samid737 Posted November 22, 2017 Share Posted November 22, 2017 This sounds like A particle system. Not sure if you can scale in one direction though. Otherwise you could update each sprite manually : //in update flamethrower.forEach(function(flame){scaleIt(flame)}); //somewhere in code function scaleIt(flame){ flame.scale.y = flame.x; // or lifespan } Link to comment Share on other sites More sharing options...
wipster Posted November 27, 2017 Author Share Posted November 27, 2017 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 More sharing options...
samid737 Posted November 27, 2017 Share Posted November 27, 2017 You could try game.physics.arcade.overlap instead of game.physics.arcade.collide(). wipster 1 Link to comment Share on other sites More sharing options...
Recommended Posts