初学Silverlight和balder,使用Silverlight4和balder 0.8.8.9建立项目, 试用coordinateAnimation创建一个方块位移的简单动画。
代码如下:
namespace _3Dani
{
public partial class MainPage : UserControl
{
Game game = null;
Balder.Objects.Geometries.Box testB = null;
public MainPage()
{
InitializeComponent();
game = new Game() { Width = 1280, Height = 600 };
game.Camera = new Camera();
game.Camera.Position = new Coordinate(150, 100, 100);
game.Camera.Target = new Coordinate(0, 0, 0);
game.Children.Add(new OmniLight() { Position = new Coordinate(0, 0, 0) });
testB = new Box();
testB.Name = "container";
testB.Dimension = new Coordinate(20, 80, 10);
testB.Position = new Coordinate(0, 0, 0);
testB.InteractionEnabled = true;
//testB.PivotPoint = new Coordinate(10, 0, 5);
testB.Color = Color.FromArgb(100, 150, 150, 150);
game.Children.Add(testB);
LayoutRoot.Children.Add(game);
}
private void play_Click(object sender, RoutedEventArgs e)
{
CoordinateAnimation ani = new CoordinateAnimation();
ani.Duration = TimeSpan.FromMilliseconds(1000);
ani.Target = testB;
ani.TargetName = "container";
ani.TargetProperty = "(Node.Position)";
ani.From = new Coordinate(0, 0, 0);
ani.To = new Coordinate(50, 0, 0);
Storyboard sb = new Storyboard();
StoryboardExtensions.SetCoordinateAnimation(sb, ani);
sb.Begin();
}
}
}
XAML页面仅有一个名为layoutRoot的Grid和一个名为play的button。
执行调试,点击play按钮以后,方块testB并不移动,此时用鼠标去旋转方块testB,方块就会突然闪到动画结束的位置。
执行调试,若先用鼠标去旋转方块testB,则动画正常执行。但这就意味着testB的InteractionEnabled属性必须设置为true,而且每次动画前都要手动旋转物体,十分不方便。
所以求问一下,要怎样才能做到点击play按钮,方块testB能直接执行动画,而不用再去拖动方块。
谢谢各位。