fps drops rapid when "boss" SpriteNode appears
@JonB thanks I did not think of that, will try to fix it Thank you
ccc last edited by
Thousands of bosses... Nightmare!!
Ok so now the fps is fixed and the boss is just one big UFO.
But now I have a new problem(No suprise there) When the boss appears he fires one laser shot,
but no more. What I'm trying to do is to make him fire lasers all the time (after all he is the boss) but I cant call such a function from
update()since the boss is a class and not in the gamefield,
My question: Is there a way in
update()to point to
spawn:boss()function (or is there a way inside the that function to create something that update all the time)
Sorry for the long post, basically: how do my boss keep firing until he is removed from scene?
omz last edited by
@Bjucha You could make the boss a property of your scene (i.e. set
self.boss = ...when you spawn it). That way, the boss could have a
last_shot_timeproperty, you check that in
update, and if it's bigger than, say, 1 second, you set
last_shot_timeto the current time, and fire a shot.
@omz hmm I really sorry but I don't really understand. what do you mean with property of my scene? and shall that property be inside the
function? or in the gamefield?
ccc last edited by ccc
def spawn_boss(self): self.boss = Boss(parent=self, position = (100, 600))
Haven't been able to get it to work yet, but Im currently trying a different approach that could work.
flight_714 last edited by
I realize this is a few weeks old, but had a few thoughts.
I typically add scene objects of a shared type to a list and then iterate over a method of their class in update.
So at the end up the enemy class init I would add 'enemies.append(self)' and then in the scene update method add 'for enemy in enemies': enemy.cooldown() or something to that to that effect.
Obviously, you'd have to write a bit more AI methods for the enemy ships, so you'd probably want to subclass them to save space.
Thanks for the tip. I did get it to work by using
counter = 10 while counter != 0: Action.wait(2) self.items.append(boss) bossfires = SpriteNode('spc:BoltBronze', parent=self) bossfires.position = boss.position + (-50, 30) bossfires.z_position = -1 b = random.uniform(10.0, 2500) actions = [A.move_to(b, 100, 2 * 2), A.remove()] bossfires.run_action(A.sequence(actions)) self.bossfires.append(bossfires) Action.wait(2) counter = counter - 1``` This works but is not really "perfect" for me. But will look at what you suggested and see if I can use it.