Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
fps drops rapid when "boss" SpriteNode appears
-
@JonB thanks I did not think of that, will try to fix it Thank you
-
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 fromupdate()
since the boss is a class and not in the gamefield,
My question: Is there a way inupdate()
to point tospawn: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? -
@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 alast_shot_time
property, you check that inupdate
, and if it's bigger than, say, 1 second, you setlast_shot_time
to 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
spawn_boss()
function? or in the gamefield? -
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.
-
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.