Beispiel #1
0
        public static Animation FromAnimationSave(AnimationChainSave animationSave)
        {
            //这个类没有构造函数,所以编译器自动会添加一个空的构造函数
            Animation toReturn = new Animation ();

            toReturn.Name = animationSave.Name;

            //读取frame(AnimationFrameSave)中的所有动画数据
            foreach (var frame in animationSave.Frames)
            {
                CCRect rectangle;

                rectangle = new CCRect (
                    frame.LeftCoordinate,
                    frame.TopCoordinate,
                    frame.RightCoordinate - frame.LeftCoordinate,
                    frame.BottomCoordinate - frame.TopCoordinate);

                var duration = TimeSpan.FromSeconds (frame.FrameLength);

                //toReturn.frames是一个frame的集合
                //每一个frame是动作的一步
                //AddFrame就是把读取到的frame添加到这个list里
                toReturn.AddFrame (rectangle, duration, flipHorizontal:frame.FlipHorizontal);
            }

            return toReturn;
        }
Beispiel #2
0
		public Player ()
		{
			LoadAnimations ("Content/animations/playeranimations.achx");

			walkLeftAnimation = animations.Find (item => item.Name == "WalkLeft");
			walkRightAnimation = animations.Find (item => item.Name == "WalkRight");

			CurrentAnimation = walkLeftAnimation;
		}
Beispiel #3
0
 public Player()
 {
     //LoadAnimations可以用是因为Player : PhysicsEntity, PhysicsEntity : AnimatedSpriteEntity, LoadAnimations是AnimatedSpriteEntity的方法
     //读取achx中所有的AnimationChain
     LoadAnimations ("Content/animations/playeranimations.achx");
     //achx文件本质是xml
     walkLeftAnimation = animations.Find (item => item.Name == "WalkLeft");
     walkRightAnimation = animations.Find (item => item.Name == "WalkRight");
     //初始化动作为向左走
     CurrentAnimation = walkLeftAnimation;
 }
Beispiel #4
0
        public Enemy()
        {
            LoadAnimations ("Content/animations/blueenemyanimations.achx");

            CurrentAnimation = animations [0];

            walkLeftAnimation = animations.Find (item => item.Name == "WalkLeft");
            walkRightAnimation = animations.Find (item => item.Name == "WalkRight");

            this.VelocityX = 0;

            this.AccelerationY = PlayerMovementCoefficients.GravityAcceleration;
        }
Beispiel #5
0
		public static Animation FromAnimationSave(AnimationChainSave animationSave)
		{
			Animation toReturn = new Animation ();

			toReturn.Name = animationSave.Name;

			foreach (var frame in animationSave.Frames)
			{
				CCRect rectangle;

				rectangle = new CCRect (
					frame.LeftCoordinate, 
					frame.TopCoordinate, 
					frame.RightCoordinate - frame.LeftCoordinate, 
					frame.BottomCoordinate - frame.TopCoordinate);

				var duration = TimeSpan.FromSeconds (frame.FrameLength);

				toReturn.AddFrame (rectangle, duration, flipHorizontal:frame.FlipHorizontal);
			}

			return toReturn;
		}
        protected void LoadAnimations(string fileName)
        {
            //把动画读到dictionary里,如果dic中已经存在则直接读取
            if (animationCache.ContainsKey (fileName))
            {
                animations = animationCache [fileName];
            }
            else
            {
                animations = new List<Animation> ();
                AnimationChainListSave acls = XmlDeserializer.Self.XmlDeserialize<AnimationChainListSave> (fileName);

                foreach (var animationSave in acls.AnimationChains)
                {
                    //从animationSave(AnimationChainSave类)中读取animation,一个一个添加到animation 的list里
                    animations.Add (Animation.FromAnimationSave (animationSave));
                }

                animationCache.Add (fileName, animations);
            }

            // This prevents the sprite from temporarily showing
            // the entire PNG for a split second.
            if (animations != null && animations.Count > 0)
            {
                CurrentAnimation = animations [0];
            }
        }