我对这段代码有疑问。
当我使用 时MoveTo
,我的骨架会在屏幕上滑动。我对原始代码做了一些小改动(这里):
- 将骨架位置锁定到特定的 Z 位置
- 增加水平速度 (X)
我使用 XNA 4.0 并将该成员称为 Draw“回调”。
所以,问题是:为什么骷髅会轻弹?
private Skeleton MoveTo2(Skeleton skToBeMoved) {
Joint newJoint = new Joint();
///Based on the HipCenter
float howMuchMoveToX = ((skToBeMoved.Joints[JointType.HipCenter].Position.X - settings_skel_offset_x) * -1) * settings_skel_offset_x_mult;
float howMuchMoveToY = (skToBeMoved.Joints[JointType.HipCenter].Position.Y - settings_skel_offset_y) * -1;
float howMuchMoveToZ = (skToBeMoved.Joints[JointType.HipCenter].Position.Z - settings_skel_offset_z) * -1;
foreach (JointType item in Enum.GetValues(typeof(JointType)))
{
newJoint = skToBeMoved.Joints[item];
SkeletonPoint pos = new SkeletonPoint()
{
X = (float)(newJoint.Position.X + (howMuchMoveToX)),
Y = (float)(newJoint.Position.Y + (howMuchMoveToY)),
Z = (float)(newJoint.Position.Z + (howMuchMoveToZ)),
};
if (XnaBasics.settings_skel_lock_z)
{
pos.Z = settings_skel_offset_z;
}
newJoint.Position = pos;
Debug.WriteLine("SkelID: "+skToBeMoved.TrackingId+ " howMuchMoveToX: " + howMuchMoveToX + " oldPosX: " + skToBeMoved.Joints[item].Position.X + " newPosX: " + newJoint.Position.X);
skToBeMoved.Joints[item] = newJoint;
}
return skToBeMoved;
}