关于生蓝色的sl游戏开发教程是用关联属性控制人物角色问题
教程上面 在一动画版上关联的属性是人物的一个关联属性 我当时就很郁闷为什么对以个关联属性作为目标而人物就动起来了呢 看了下那人物类的属性里也没设置什么
我把具体代码贴出来
Storyboard storyboard; //创建移动动画故事板
//直线移动
private void NormalMoveTo(Point p) {
//总的移动花费
double totalcost = Math.Sqrt(Math.Pow(p.X - Spirit.X, 2) + Math.Pow(p.Y - Spirit.Y, 2)) / GridSize * UnitMoveCost;
//创建移动动画
storyboard = new Storyboard();
//创建X轴方向属性动画
DoubleAnimation doubleAnimation = new DoubleAnimation(
Spirit.X,
p.X,
new Duration(TimeSpan.FromMilliseconds(totalcost))
);
Storyboard.SetTarget(doubleAnimation, Spirit);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("X"));
storyboard.Children.Add(doubleAnimation);
//创建Y轴方向属性动画
doubleAnimation = new DoubleAnimation(
Spirit.Y,
p.Y,
new Duration(TimeSpan.FromMilliseconds(totalcost))
);
Storyboard.SetTarget(doubleAnimation, Spirit);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Y"));
storyboard.Children.Add(doubleAnimation);
//创建主角朝向属性动画
double direction = Super.GetDirectionByTan(p.X, p.Y, Spirit.X, Spirit.Y);
doubleAnimation = new DoubleAnimation(
direction,
direction,
new Duration(TimeSpan.FromMilliseconds(totalcost))
);
Storyboard.SetTarget(doubleAnimation, Spirit);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Direction"));
storyboard.Children.Add(doubleAnimation);
//动画播放
storyboard.Begin();
}
大家注意里面
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Y"));
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("X"));
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Direction"));
一般我们相对于动画版本的移动的写法会是
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canver.Left)"));
可是这里的目标属性却是一个X,Y关联属性
下面我把这个关联属性的定义贴出来
/// <summary>
/// 精灵X坐标(关联属性)
/// </summary>
public double X {
get { return (double)GetValue(XProperty); }
set { SetValue(XProperty, value); }
}
public static readonly DependencyProperty XProperty = DependencyProperty.Register(
"X", //属性名
typeof(double), //属性类型
typeof(QXSpirit), //属性主人类型
new FrameworkPropertyMetadata(
(double)0, //初始值0
FrameworkPropertyMetadataOptions.None, //不特定界面修改
//不需要属性改变回调
null,//new PropertyChangedCallback(QXSpiritInvalidated),
//不使用强制回调
null
)
);
/// <summary>
/// 精灵Y坐标(关联属性)
/// </summary>
public double Y {
get { return (double)GetValue(YProperty); }
set { SetValue(YProperty, value); }
}
public static readonly DependencyProperty YProperty = DependencyProperty.Register(
"Y",
typeof(double),
typeof(QXSpirit),
new FrameworkPropertyMetadata(
(double)0,
FrameworkPropertyMetadataOptions.None,
null,
null
)
);
/// <summary>
/// 精灵当前朝向:0朝上4朝下,顺时针依次为0,1,2,3,4,5,6,7(关联属性)
/// </summary>
public double Direction {
get { return (double)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty, value); }
}
public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register(
"Direction",
typeof(double),
typeof(QXSpirit)
);
他没去设置想对于Canver的位置属性
我实在不知道他在哪设置了想对于Canver的位置移动
大家能帮帮我研究下嘛
我把源码的下载地址贴出来
http://www.cnblogs.com/alamiye010/archive/2009/06/17/1505346.html
是第一部分源码
在里面的Windows20.XAML里
[解决办法]
加入QQ群73068105(1群)或20167206(2群)或92298919(3群),或发送E-Mail到alamiye@163.com给作者,深蓝会给你回复啦~