Exemple #1
0
        public static TileAnimation LoadFromJson(JToken json, Point2D basePos)
        {
            var ani = new TileAnimation();

            // RPG Maker XP animations are based on one tileset
            var tilesetSource = new TileCellSource(json["graphic"].ToString(), 0, 0, Constants.AnimationTilesetWidth, Constants.AnimationTilesetHeight);
            var tileset       = EngineCore.ContentLoader.GetAnimationTileset(tilesetSource.TextureIndex);
            var tilesPerRow   = tileset.Width / tilesetSource.Width;

            var frames = (JArray)json["frames"];

            foreach (var frame in frames)
            {
                var frameImages = (JArray)frame;
                var tileFrame   = new TileAnimationFrame();
                foreach (var frameImage in frameImages)
                {
                    /*
                     * pattern: 1,		// 1-based tile index
                     * x: 0,			// center-based x-offset
                     * y: 16,			// center-based y-offset
                     * zoom: 30,		// 100-based scale
                     * rotation: 0,		// 360-degree
                     * opacity: 100		// 255 = full visible, 0 = full trans
                     */
                    // Make index 0-based!
                    var patIndex    = (int)(frameImage["pattern"]) - 1;
                    var patX        = (int)(frameImage["x"]);
                    var patY        = (int)(frameImage["y"]);
                    var patZoom     = (int)(frameImage["zoom"]);
                    var patRotation = (int)(frameImage["rotation"]);
                    var patOpacity  = (int)(frameImage["opacity"]);

                    if (patIndex > 0)
                    {
                        tilesetSource.X = (patIndex % tilesPerRow) * tilesetSource.Width;
                        tilesetSource.Y = (patIndex / tilesPerRow) * tilesetSource.Width;
                    }
                    else
                    {
                        tilesetSource.X = 0;
                        tilesetSource.Y = 0;
                    }
                    var scale        = patZoom / 100f;
                    var pos          = new Point2D(patX + basePos.X, patY + basePos.Y);
                    var mirror       = SpriteEffects.None;
                    var col          = new Color(Color.White.R, Color.White.G, Color.White.B, patOpacity);
                    var isBackground = false;                     // TODO: How does RPG Maker handle this?
                    var rot          = (float)patRotation;
                    var pattern      = new TileAnimationFrameImage(tilesetSource.Clone() as TileCellSource, scale, pos, mirror, col, rot, isBackground);
                    tileFrame.Add(pattern);
                }

                ani.Frames.Add(tileFrame);
            }

            return(ani);
        }
		public TileAnimationFrameImage(TileCellSource source, float scale, Point2D pos, SpriteEffects mirror, Color col, float rot, bool isBg) {
			TextureSource = source;
			Scale = scale;
			Offset = new Point2D(pos.X, pos.Y);
			Mirror = mirror;
			Rotation = rot;
			Color = col;
			IsBackground = isBg;
		}
 public TileAnimationFrameImage(TileCellSource source, float scale, Point2D pos, SpriteEffects mirror, Color col, float rot, bool isBg)
 {
     TextureSource = source;
     Scale         = scale;
     Offset        = new Point2D(pos.X, pos.Y);
     Mirror        = mirror;
     Rotation      = rot;
     Color         = col;
     IsBackground  = isBg;
 }
Exemple #4
0
        private static TileCellSource GetTextureSource(string name)
        {
            var parts = name.Split(new[] { '_' });
            var src   = new TileCellSource {
                TextureIndex = FileLists.Instance.AnimationTilesets[int.Parse(parts[0])].Filename,
                Width        = Constants.AnimationTilesetWidth,
                Height       = Constants.AnimationTilesetHeight,
                X            = (int.Parse(parts[1]) * Constants.AnimationTilesetWidth),
                Y            = (int.Parse(parts[2]) * Constants.AnimationTilesetHeight)
            };

            return(src);
        }
Exemple #5
0
		public static TileAnimation LoadFromJson(JToken json, Point2D basePos) {
			var ani = new TileAnimation();

			// RPG Maker XP animations are based on one tileset
			var tilesetSource = new TileCellSource(json["graphic"].ToString(), 0, 0, Constants.AnimationTilesetWidth, Constants.AnimationTilesetHeight);
			var tileset = EngineCore.ContentLoader.GetAnimationTileset(tilesetSource.TextureIndex);
			var tilesPerRow = tileset.Width / tilesetSource.Width;

			var frames = (JArray)json["frames"];
			foreach (var frame in frames) {
				var frameImages = (JArray)frame;
				var tileFrame = new TileAnimationFrame();
				foreach (var frameImage in frameImages) {
					/*
					 * pattern: 1,		// 1-based tile index
					 * x: 0,			// center-based x-offset
					 * y: 16,			// center-based y-offset
					 * zoom: 30,		// 100-based scale
					 * rotation: 0,		// 360-degree
					 * opacity: 100		// 255 = full visible, 0 = full trans
					 */
					// Make index 0-based!
					var patIndex = (int)(frameImage["pattern"]) - 1;
					var patX = (int)(frameImage["x"]);
					var patY = (int)(frameImage["y"]);
					var patZoom = (int)(frameImage["zoom"]);
					var patRotation = (int)(frameImage["rotation"]);
					var patOpacity = (int)(frameImage["opacity"]);

					if (patIndex > 0) {
						tilesetSource.X = (patIndex % tilesPerRow) * tilesetSource.Width;
						tilesetSource.Y = (patIndex / tilesPerRow) * tilesetSource.Width;
					} else {
						tilesetSource.X = 0;
						tilesetSource.Y = 0;
					}
					var scale = patZoom / 100f;
					var pos = new Point2D(patX + basePos.X, patY + basePos.Y);
					var mirror = SpriteEffects.None;
					var col = new Color(Color.White.R, Color.White.G, Color.White.B, patOpacity);
					var isBackground = false; // TODO: How does RPG Maker handle this?
					var rot = (float)patRotation;
					var pattern = new TileAnimationFrameImage(tilesetSource.Clone() as TileCellSource, scale, pos, mirror, col, rot, isBackground);
					tileFrame.Add(pattern);
				}

				ani.Frames.Add(tileFrame);
			}

			return ani;
		}