我正在创建一系列动作来回放录制的手势。如果我只是平移序列,它会全速播放。如果我只旋转,它会全速播放。如果我只是缩放它全速播放。但是,如果我平移然后旋转,则旋转播放大约一半的速度。如果我旋转然后平移,平底锅以大约一半的速度运行。这是播放功能。 RecordData只是一个包含时间,位置,旋转,比例信息的对象。
-(void) Play
{
int count = [m_MoveTos count];
if (count < 2)
{
return;
}
[m_Actor stopAllActions];
[m_Actions removeAllObjects];
RecordData* start = [m_MoveTos objectAtIndex:0];
m_Actor.position = start.Pos;
m_Actor.rotation = start.Rotate;
m_Actor.scale = start.Scale;
NSLog(@"Starting with %d nodes.", [m_MoveTos count]);
NSLog(@"Actor Start Position:%f, %f Rotation:%f, Scale:%f", m_Actor.position.x, m_Actor.position.y, m_Actor.rotation, m_Actor.scale);
float lastTime = 0;
RecordData* lastData = start;
//Skip start
for(int i = 1; i < count; ++i)
{
bool delay = true;
RecordData* rData = [m_MoveTos objectAtIndex:i];
float delta = rData.Time - lastTime;
if(rData.Pos.x != lastData.Pos.x || rData.Pos.y != lastData.Pos.y)
{
CCAction* moveAction = [CCMoveTo actionWithDuration:delta position:rData.Pos];
[m_Actions addObject:moveAction];
delay = false;
}
if (rData.Rotate != lastData.Rotate)
{
// Put this in Record data
float degrees = rData.Rotate;
int sign = degrees/ABS(degrees);
degrees = ABS(degrees);
while (degrees > 360)
{
degrees -= 360;
}
degrees *= sign;
NSLog(@"Rotation %f", degrees);
CCAction* rotAction = [CCRotateTo actionWithDuration:delta angle:degrees];
[m_Actions addObject:rotAction];
delay = false;
}
if (rData.Scale != lastData.Scale)
{
CCAction* scaleAction = [CCScaleTo actionWithDuration:delta scale:rData.Scale];
[m_Actions addObject:scaleAction];
delay = false;
}
if(delay)
{
CCActionInterval* delayTime = [CCDelayTime actionWithDuration:delta];
[m_Actions addObject:delayTime];
}
delay = true;
lastTime = rData.Time;
}
if([m_Actions count] < 2)
{
return;
}
CCAction* seq = [CCSequence actionsWithArray:[m_Actions getNSArray]];
[m_Actor runAction:seq];
}
我有什么遗失的吗?
谢谢, 吉姆
答案 0 :(得分:0)
混合动作类型似乎是个问题。我现在有一个不同的位置,旋转和比例动作序列。它现在运行良好。