在应用程序中运行轨道
在 UnigineEditor 中创建基于轨道的动画后,需要在应用程序中播放它们。要将此功能添加到您的项目中,请将以下代码添加到 world 脚本中:
#include <core/systems/tracker/tracker.h>
Unigine::Tracker::TrackerTrack track;
float time, min_time, max_time, unit_time;
int init() {
// use the Tracker namespace
using Unigine::Tracker;
// create a Tracker instance that will play the tracks
Tracker tracker = new Tracker();
// load the required tracks from a file
track = tracker.loadTrack("samples/tracker/tracks/render_00.track");
// get the start time of the track (in units)
min_time = track.getMinTime();
// get the end time of the track (in units)
max_time = track.getMaxTime();
// get the duration of the track unit (in seconds)
unit_time = track.getUnitTime();
// set the initial time to play the tracks
time = track.getMinTime();
return 1;
}
int update() {
if(track == NULL) return 1;
// update the tracks animation time
time += engine.game.getIFps() / unit_time;
time = min_time + ((time - min_time)) % (max_time - min_time);
// set animation time for tracks (time values outside the [mintime, maxtime] range are clamped automatically)
if(engine.game.isEnabled()) track.set(time);
return 1;
}
[MinTime, MaxTime] 范围之外的时间值会被自动限制。
最新更新:
2024-04-19
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)