示例#1
0
 public void CreateSpriteSheetAnimationWithNewTexture()
 {
     var data = new ImageCreationData(new Size(8, 8)) { BlendMode = BlendMode.Opaque };
     var image = ContentLoader.Create<Image>(data);
     FillImage(image);
     var animationData = new SpriteSheetAnimationCreationData(image, 2, new Size(2, 2));
     var texturedShader = ContentLoader.Load<Shader>(Shader.Position2DUV);
     var newMaterial = new SpriteSheetAnimation(animationData).CreateMaterial(texturedShader);
     new Sprite(newMaterial, Rectangle.HalfCentered);
 }
 public ContentMetaData CreateMetaDataFromSpriteSheetAnimation(string animationName,
     SpriteSheetAnimation spriteSheetAnimation)
 {
     var contentMetaData = new ContentMetaData();
     SetDefaultValues(contentMetaData, animationName);
     contentMetaData.Type = ContentType.SpriteSheetAnimation;
     contentMetaData.Values.Add("DefaultDuration",
         spriteSheetAnimation.DefaultDuration.ToString(CultureInfo.InvariantCulture));
     contentMetaData.Values.Add("SubImageSize", spriteSheetAnimation.SubImageSize.ToString());
     contentMetaData.Values.Add("ImageName", spriteSheetAnimation.Image.Name);
     return contentMetaData;
 }
		private Material CreateDefaultMaterial2D()
		{
			var imageData = new ImageCreationData(new Size(8.0f, 8.0f));
			imageData.DisableLinearFiltering = true;
			var image = ContentLoader.Create<Image>(imageData);
			var colors = new Color[8 * 8];
			for (int i = 0; i < 8; i++)
				for (int j = 0; j < 8; j++)
					if ((i + j) % 2 == 0)
						colors[i * 8 + j] = Color.LightGray;
					else
						colors[i * 8 + j] = Color.DarkGray;
			image.Fill(colors);
			spriteSheetAnimation =
				new SpriteSheetAnimation(new SpriteSheetAnimationCreationData(image, 1, new Size(2, 2)));
			return new Material(ShaderFlags.Position2DTextured, "")
			{
				SpriteSheet = spriteSheetAnimation
			};
		}
		public void ShowSpritesheetAnimation()
		{
			var image = ContentLoader.Load<Image>(ImageList[0]);
			if (SubImageSize.Width == 0 || SubImageSize.Height == 0)
			{
				subImageSize = image.PixelSize;
				RaisePropertyChanged("SubImageSize");
			}
			spriteSheetAnimation =
				new SpriteSheetAnimation(new SpriteSheetAnimationCreationData(image, Duration, SubImageSize));
			var material = new Material(ShaderFlags.Position2DTextured, "")
			{
				SpriteSheet = spriteSheetAnimation
			};
			renderExample = new Sprite(material,
				Rectangle.FromCenter(0.5f, 0.5f, 0.5f * SubImageSize.AspectRatio, 0.5f));
		}