コード例 #1
0
ファイル: AGSAnimation.cs プロジェクト: tzachshabtay/MonoAGS
        public IAnimation Clone()
        {
            AGSAnimation clone = (AGSAnimation)MemberwiseClone();

            clone.Frames = new List <IAnimationFrame> (Frames.Count);
            foreach (var frame in Frames)
            {
                clone.Frames.Add(frame.Clone());
            }
            return(clone);
        }
コード例 #2
0
ファイル: GLGraphicsFactory.cs プロジェクト: saizant/MonoAGS
        private AGSAnimation getAnimation(string samplePath, IAnimationConfiguration animationConfig, int resourcesCount)
        {
            if (resourcesCount == 0 && samplePath != null)
            {
                throw new InvalidOperationException($"Failed to load animation from: {samplePath}");
            }
            animationConfig = animationConfig ?? new AGSAnimationConfiguration();
            AGSAnimationState state     = new AGSAnimationState();
            AGSAnimation      animation = new AGSAnimation(animationConfig, state, resourcesCount);

            return(animation);
        }
コード例 #3
0
ファイル: GLGraphicsFactory.cs プロジェクト: saizant/MonoAGS
        private void addAnimationFrame(IImage image, AGSAnimation animation)
        {
            if (image == null)
            {
                return;
            }
            ISprite sprite = GetSprite();

            sprite.Image = image;
            AGSAnimationFrame frame = new AGSAnimationFrame(sprite);

            animation.Frames.Add(frame);
        }
コード例 #4
0
ファイル: GLGraphicsFactory.cs プロジェクト: saizant/MonoAGS
        private IAnimation loadAnimationFromResources(string samplePath, List <IResource> resources,
                                                      IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            AGSAnimation animation = getAnimation(samplePath, animationConfig, resources.Count);

            foreach (IResource resource in resources)
            {
                var image = loadImage(resource, loadConfig);
                addAnimationFrame(image, animation);
            }
            animation.Setup();
            return(animation);
        }
コード例 #5
0
        public IAnimation ToItem(AGSSerializationContext context)
        {
            AGSAnimation animation = new AGSAnimation(Configuration.ToItem(context), State.ToItem(context),
                                                      Frames == null ? 0 : Frames.Count);

            if (Frames != null)
            {
                foreach (var frame in Frames)
                {
                    animation.Frames.Add(frame.ToItem(context));
                }
            }
            return(animation);
        }
コード例 #6
0
		public void SetupAnimationTest(LoopingStyle looping, int expectedFrame, bool expectedBackwards)
		{
            AGSAnimationConfiguration config = new AGSAnimationConfiguration { Looping = looping, DelayBetweenFrames = 0 };
			AGSAnimationState state = new AGSAnimationState ();
			AGSAnimation animation = new AGSAnimation (config, state);
			for (int i = 0; i < 5; i++)
			{
				animation.Frames.Add(getFrame(i * 2));
			}

			animation.Setup();

			Assert.AreEqual(expectedFrame, state.CurrentFrame);
			Assert.AreEqual(0, state.CurrentLoop);
			Assert.AreEqual(expectedBackwards, state.RunningBackwards);
			Assert.AreEqual(expectedFrame * 2, state.TimeToNextFrame);
		}
コード例 #7
0
        private void getSpriteSheetData(IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig,
                                        out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX,
                                        out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep,
                                        out AGSAnimation animation)
        {
            cellsInRow = bitmap.Width / spriteSheet.CellWidth;
            cellsInCol = bitmap.Height / spriteSheet.CellHeight;
            cellsTotal = cellsInRow * cellsInCol;

            int startRow, startCol;

            getOrder(spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep);

            cellX       = startCol;
            cellY       = startRow;
            cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min(spriteSheet.CellsToGrab, cellsTotal);
            animation   = new AGSAnimation(animationConfig, new AGSAnimationState(), cellsToGrab);
        }
コード例 #8
0
		public void NextFrameTest(LoopingStyle looping, int loops, int currentFrame, int currentLoop, bool runningBackwards, int expectedFrame, int expectedLoop, bool expectedBackwards)
		{
            AGSAnimationConfiguration config = new AGSAnimationConfiguration { Looping = looping, Loops = loops, DelayBetweenFrames = 0 };
			AGSAnimationState state = new AGSAnimationState {
				CurrentFrame = currentFrame,
				CurrentLoop = currentLoop,
				RunningBackwards = runningBackwards,
				TimeToNextFrame = currentFrame * 2
			};
			AGSAnimation animation = new AGSAnimation (config, state);
			for (int i = 0; i < 5; i++)
			{
				animation.Frames.Add(getFrame(i * 2));
			}

			animation.NextFrame();

			Assert.AreEqual(expectedFrame, state.CurrentFrame);
			Assert.AreEqual(expectedLoop, state.CurrentLoop);
			Assert.AreEqual(expectedBackwards, state.RunningBackwards);
			Assert.AreEqual(expectedFrame * 2, state.TimeToNextFrame);
		}
コード例 #9
0
        private void addAnimationFrame (IImage image, AGSAnimation animation)
		{
			if (image == null) return;
			ISprite sprite = GetSprite ();
			sprite.Image = image;
			AGSAnimationFrame frame = new AGSAnimationFrame (sprite);
			animation.Frames.Add (frame);
		}
コード例 #10
0
		private AGSAnimation getAnimation (IAnimationConfiguration animationConfig, int resourcesCount)
		{
			animationConfig = animationConfig ?? new AGSAnimationConfiguration ();
			AGSAnimationState state = new AGSAnimationState ();
			AGSAnimation animation = new AGSAnimation (animationConfig, state, resourcesCount);
			return animation;
		}
コード例 #11
0
		private void getSpriteSheetData (IBitmap bitmap, ISpriteSheet spriteSheet, IAnimationConfiguration animationConfig,
		                                out int cellsInRow, out int cellsInCol, out int cellsTotal, out int cellX,
		                                 out int cellY, out int cellsToGrab, out Point mainStep, out Point secondStep, 
		                                 out AGSAnimation animation)
		{
			cellsInRow = bitmap.Width / spriteSheet.CellWidth;
			cellsInCol = bitmap.Height / spriteSheet.CellHeight;
			cellsTotal = cellsInRow * cellsInCol;

			int startRow, startCol;
			getOrder (spriteSheet.Order, cellsInRow, cellsInCol, out startRow, out startCol, out mainStep, out secondStep);

			cellX = startCol;
			cellY = startRow;
			cellsToGrab = spriteSheet.CellsToGrab < 0 ? cellsTotal : Math.Min (spriteSheet.CellsToGrab, cellsTotal);
			animation = new AGSAnimation (animationConfig, new AGSAnimationState (), cellsToGrab);
		}