Popular Content

Showing content with the highest reputation on 07/19/20 in all areas

  1. 1 point
    Hi, in our game we're spawning enemies in some timely manner. The main game Scene implements a timer which takes care of spawning new instance of `Phaser.GameObjects.Sprite` every second. There are max. 13 enemies at once, each enemy is creating his own timer to follow a schedule when to attack etc. Example of constructor of the enemy subclass constructor ({ scene, hole }) { super(scene, params ) this.timer = this.scene.time.addEvent({ startAt: 1, delay: 3000, loop: true, callback: this.enemyTicker, callbackScope: this }) } For example this enemy type attacks every 3 seconds and his ticker implementation is following alienTicker() { this.attack() } attack() { super.attack() this.play('simple_attack').anims.chain('simple_idle') this.play('simple_attack').once('animationcomplete-simple_attack', () => { this.scene.onAttack() }) } On tapping the enemy I need to destroy the instance tap() { super.tap() // Remove interaction this.removeInteractive() this.scene.onKill(this) this.play('simple_disappear').once('animationcomplete-simple_disappear', () => { this.finalize() }) } finalize() { this.hole.onAlienDestroy() this.timer.remove() this.anims.remove() this.destroy() } In most cases it works but if I time my tap so that the enemy is about to attack and destroy him, I get the following exception Uncaught TypeError: Cannot read property 'load' of null at Animation.load (Animation.js:420) at Animation._startAnimation (Animation.js:583) at Animation.play (Animation.js:530) at _default.play (Sprite.js:134) at _default.attack (SimpleAlien.js:78) at _default.alienTicker (SimpleAlien.js:118) at Clock.update (Clock.js:322) at EventEmitter.emit (index.js:203) at Systems.step (Systems.js:379) at SceneManager.update (SceneManager.js:563) So clearly the problem is with the attack animation trying to be played but the instance doesn't exist anymore. Is there any other way how to stop animation manager from playing the animation than `this.anims.remove()`? Thanks EDIT: The problem is in my sequence of the animations. I was cleaning the object when the dying animation ended but I should have stopped the timer on the start of the dying animation this.play('simple_explode').once('animationstart-simple_explode', () => { this.preclean() }) this.play('simple_explode').once('animationcomplete-simple_explode', () => { this.postclean() })
  2. 1 point
    Hi, thanks for reply, I've finally found the reason of the bad performance, I set the antialias to true in PixiJS, while it is false in createJs even though most of my assets are sprites, apparently the performance can still be affected.
  3. 1 point


    Hi, I've achieved this before in two different ways Long way but good performance after initial run: 1. Create a Pixi.Container 2. Add the body sprite 3. Add the armour sprite 4. use renderTexture to turn this into a texture and store it 5. Repeat this for every direction 6. When character changes direction, swap to the previously mentioned textures Spine way but not as good performance with many objects: 1. Create a spine of the character (build it up from scratch with skeleton and sprites) 2. With PixiJS, swap the slots of the armour when required, and set the animations for different directions Edit: There are other ways of course, just setting the position of both the character and its armour sprite to be the same etc, anchoring... But I avoided them. Added below Container method (probably works quite well actually): 1. Create a Pixi.Container call this player 2. Add the body sprite to it, call it body (player.body) (player.body = new Pixi.Sprite(etc) OR Animated sprite then player.addChild(player.body)) 3. Add the armour sprite to it, call it armour (player.armour, repeat above) 4. When updating player (the pixi.container) position the body and armour will move with it, since its in the same container 5. When the player swaps direction, swap both player.body and player.armour texture (if using an animated sprite, use gotoAndStop i guess) Whichever approach you take with it, shouldn't be a problem really. Trust in pixi.
  4. 1 point

    Stomp mechanic on collision

    flicker actually takes an optional callback function as argument, so you can directly remove the child from there or do whatever else you need when the effect is over. also it's good practice to disable collision on that object at that point, you can do it using setCollisionMask (at least this is how I do it), but using your own variable also do the job see the example below for both : https://github.com/melonjs/melonJS/blob/master/examples/platformer/js/entities/enemies.js#L78-L102