setColorTransform flickering when applies on a typed group
-
Hi!
I am trying to create something like Galaxian.
I have enemy spaceships that I store invar enemies:FlxTypedGroup<Enemy>;
When bullet overlaps an enemy I callpublic function onOverlap() { HP--; this.setColorTransform(1, 0.4 + (HP / 10), 0.4 + (HP / 10)); if (HP <= 0) { kill(); } }
this is what happens in the playstate loop:
override public function update(elapsed:Float) { super.update(elapsed); FlxG.overlap(enemies, playerBullets, onOverlap); } function onOverlap(enemy:Enemy, bullet:Bullet) { if (enemy.alive && enemy.exists && bullet.alive && bullet.exists) { enemy.onOverlap(); if (enemy.alive == false) { explosion = new Explosion(enemy.x, enemy.y); add(explosion); explosion.Perform(); } bullet.kill(); } }
Seems I do everything right but after the first overlap all my enemy spaceships starts flickering and disappear...
And it looks like a complete chaos.
I have no idea how I can fix the issue... could anybody help to resolve?
-
Solved.
As I am using typed group to store all my enemy ships I have to set Unique for loadGraphic in my Enemy class everytime I create a new instance.
Otherwise HF optimizes memory usage and store only one graphic object in vertex buffer and when I try to repaint one particular enemy it overloads the vertex buffer.
The following resolved the issue (one small 'true' at the end):loadGraphic("assets/images/enemy.png", false, 24, 22, true);