- Panda3d 1.7 Game Developer's Cookbook
- Christoph Lang
- 361字
- 2021-04-09 21:21:47
Making animations fit to intervals
Intervals are a very powerful feature of Panda3D, which you can see in the recipe Controlling actions using intervals. In this recipe you will go one step beyond and see how to efficiently control animations when used in conjunction with intervals.
Getting ready
If you haven't already, please read how to use intervals in Controlling actions using intervals and follow the steps of that recipe.
How to do it...
This recipe consists of the following tasks:
- Open
Application.py
. - Delete the line
self.panda.loop("walk")
. - Find the following part of the code:
self.pandaWalk = Sequence(self.walkIval1, self.turnIval1, self.colorIval, self.walkIval2, self.turnIval2, self.colorIval) self.pandaWalk.loop()
- Replace it with the following code:
self.pandaAnim = ActorInterval(self.panda, "walk", loop = 1, duration = 5) self.pandaMove = Sequence(self.walkIval1, self.turnIval1, self.colorIval, self.walkIval2, self.turnIval2, self.colorIval) self.pandaWalk = Parallel(self.pandaAnim, self.pandaMove) self.pandaWalk.loop()
How it works...
The panda is moving just like before, but now an ActorInterval
we create in the highlighted line of the code controls animation playback. We set the animation to loop and to play over the duration of five seconds. Finally, the animation-controlling ActorInterval
and the Sequence
of transformations are made part of a Parallel
that plays the two intervals at the same time.
There's more...
The actor interval constructor can take a range of optional parameters besides loop
and duration
that were already presented in the sample code. Let's take a look at what else you can do with ActorInterval
:
Instead of duration
, you can use startTime
and endTime
to define more precisely when to start and stop playing the animation.
The playrate
parameter lets you set the animation playback speed. Also note that if playrate
is a negative value, the animation is played backwards.
You can specify a sub range of the animation to be played by setting startFrame
and endFrame
. Also, if you want to loop an animation range, set constrainedLoop
to one instead of loop
.
In the following line of code, all these options have been applied to our sample code to loop the first second of the walk animation at a very low rate:
self.pandaAnim = ActorInterval(self.panda, "walk", startTime = 0, endTime = 1, playrate = 0.1, constrainedLoop = 1, duration = 5)
- Midjourney AI繪畫藝術(shù)創(chuàng)作教程:關(guān)鍵詞設(shè)置、藝術(shù)家與風(fēng)格應(yīng)用175例
- Hadoop核心技術(shù)
- 中文版After Effects 2021入門教程
- Adobe創(chuàng)意大學(xué)Illustrator產(chǎn)品專家認證標(biāo)準(zhǔn)教材(CS6修訂版)
- 視覺封王:Photoshop CC 2019立體化教程(素材+視頻+教案)
- 專業(yè)級音樂制作理論與實踐Pro Tools:從入門到應(yīng)用
- Photoshop CC入門與進階
- NetLogo多主體建模入門
- NetSuite OneWorld Implementation 2011 R2
- Cinema 4D基礎(chǔ)培訓(xùn)教材
- 傳奇:ZBrush數(shù)字雕刻大師之路(第2版)
- jQuery 1.3 with PHP
- Photoshop CS6淘寶美工完全實例教程(全視頻彩色版)
- UG NX 12.0中文版自學(xué)視頻教程
- 工作型PPT該這樣做