Silverlight游戏开发学习笔记(一)

一、Silverlight中的三种动画:
       Storyboard动画的创建必须依赖关联属性(依赖属性),为创建一系列高度连续变化的动画提供解决方案,甚至实现更为复杂的KeyFrame关键帧动画。

       CompositionTarget动画适合基于全局画面刷新时的时时属性更改,比如游戏循环等等。

       DispatcherTimer动画则非常适合运用于对象的自有动作动画中,例如精灵的移动,战斗,施法动作;魔法播放动画等等。

二、“八朝向”算法
/// <summary>
        /// 计算当前坐标与目标点之间的正切值获取朝向
        /// </summary>
        /// <param name="current">当前坐标</param>
        /// <param name="target">目标坐标</param>
        /// <returns>朝向代号0、1、2、3、4、5、6、7</returns>
        public int GetDirection(Point current, Point target) {
            double tan = (target.Y - current.Y) / (target.X - current.X);
            if (Math.Abs(tan) >= Math.Tan(Math.PI * 3 / 8) && target.Y <= current.Y) {
                return 0;
            } else if (Math.Abs(tan) > Math.Tan(Math.PI / 8) && Math.Abs(tan) < Math.Tan(Math.PI * 3 / 8) && target.X > current.X && target.Y < current.Y) {
                return 1;
            } else if (Math.Abs(tan) <= Math.Tan(Math.PI / 8) && target.X >= current.X) {
                return 2;
            } else if (Math.Abs(tan) > Math.Tan(Math.PI / 8) && Math.Abs(tan) < Math.Tan(Math.PI * 3 / 8) && target.X > current.X && target.Y > current.Y) {
                return 3;
            } else if (Math.Abs(tan) >= Math.Tan(Math.PI * 3 / 8) && target.Y >= current.Y) {
                return 4;
            } else if (Math.Abs(tan) > Math.Tan(Math.PI / 8) && Math.Abs(tan) < Math.Tan(Math.PI * 3 / 8) && target.X < current.X && target.Y > current.Y) {
                return 5;
            } else if (Math.Abs(tan) <= Math.Tan(Math.PI / 8) && target.X <= current.X) {
                return 6;
            } else if (Math.Abs(tan) > Math.Tan(Math.PI / 8) && Math.Abs(tan) < Math.Tan(Math.PI * 3 / 8) && target.X < current.X && target.Y < current.Y) {
                return 7;
            } else {
                return 0;
            }
        }

三、速度系数的理解
        关于速度系数的理解。
        数学公式:s=v*t
        而这里(k为速度系数):s*k=t。这样,s/t=1/k。也就是v=1/k。距离乘以系数得到时间。
        这样,速度系数越大,单位时间内移动的距离就小(速度),物体运动的就越慢。
        再来看这个公式:s*k=t。是不是系数“k”越大,所用时间“t”就越大。“s”距离一定,时间长了,速度自然慢。

朋友,如果您有什么真知灼见,可以加“新浪微博”/MSN哦,starrycheng@live.com,我们大家一起讨论,一起研究。

最后,帮忙加一分吧,想整个空间系统。

原文地址:https://www.cnblogs.com/ssol/p/2231371.html