[英]Animator in Ursina
I want to create a class that create an Entity when is called.我想创建一个在被调用时创建实体的类。 In this class i have an update functioun where i traied to animate the entity, but the self.animate_position_x doesn't work and i get the error: "duration" is not defined.My code is:在这个类中,我有一个更新功能,我可以在其中为实体设置动画,但 self.animate_position_x 不起作用,我收到错误:“duration”未定义。我的代码是:
class enemy(Entity):
def __init__(self,x,y):
super().__init__()
self.model = 'quad'
self.color = color.green
self.collider = 'box'
self.scale = (1,2)
self.position = (x,y)
self.posx = x
def update(self):
self.animate_x = (12, duration == 1)
touch = self.intersects(ignore =(ground,player,))
dist = distance(self,player)
if touch.hit:
destroy(self,delay = 0.05)
How can i animate in a class?我如何在课堂上制作动画? PS I use Ursina engine PS我使用Ursina引擎
First of all you will need to fix some syntax problems ( duration == 1
should be duration = 1
, but you only need to put 1
.首先,您需要解决一些语法问题( duration == 1
应该是duration = 1
,但您只需要输入1
。
Then, everything should work.然后,一切都应该工作。 I just fixed some animation problems and then this is all done.我刚刚修复了一些动画问题,然后就完成了。
from ursina import *
from first_person_controller import FirstPersonController
app = Ursina()
class enemy(Entity):
def __init__(self,x,y):
super().__init__()
self.model = 'quad'
self.color = color.green
self.collider = 'box'
self.scale = (1,2)
self.position = (x,y)
self.posx = x
def update(self):
self.animate_x(1, curve=curve.in_expo)
touch = self.intersects(ignore =(player,ground,))
dist = distance(self,player)
if touch.hit:
destroy(self,delay = 0.05)
player = FirstPersonController(model = 'sphere',
origin = (0, -.5, 0),
collider = 'box',
)
ground = Entity(model='plane', texture='grass', collider = 'box', scale=10)
enemy(0,0)
app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.