In a project I am working on, I have multiple classes in which I wish to each have an update function when an object is created. How do I get these update functions to run every frame? i.e for this example code, how do I get both class a and b to run update functions?
JavaScript
x
16
16
1
from ursina import *
2
app = Ursina()
3
4
class a:
5
def update(self):
6
print("a updating")
7
8
class b:
9
def update(self):
10
print("b updating")
11
12
a = a()
13
b = b()
14
15
app.run()
16
At the moment neither function gets run. Any help is appreciated
Advertisement
Answer
For update to run automatically it has to be on an Entity. Simply inherit Entity like this:
JavaScript
1
4
1
class A(Entity):
2
def update(self):
3
print('update')
4
The way this works is that when you instantiate an Entity, ursina will add it to a list (scene.entities). Every frame ursina will loop through that list and call entity.update() if that entity has a method named update