Skip to content
Advertisement

Ursina update function within class

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

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

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

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement