private void ResetAnimation() { active = true; if (spriteSheets.Count != 0) { spriteSheetInfo = CurrentAnimation.info; } sourceRect = new Rectangle(0, 0, spriteSheetInfo.FrameWidth, spriteSheetInfo.FrameHeight); elapsedTime = 0; currentFrame = 0; }
public SpriteSheet AddSpriteSheet(Texture2D spriteSheet, SpriteSheetInfo info, int frameCount, int columns, int rows, SpriteSheet.Directions direction, long frameTime, bool loop) { return(new SpriteSheet(spriteSheet, info, frameCount, columns, rows, direction, TimeSpan.FromMilliseconds(frameTime).Ticks, loop)); }
public Sprite(GraphicsDeviceManager graphics, SpriteSheetInfo spriteSheetInfo) { isAnimated = true; drawRect = new Rectangle((int)Math.Round(position.X), (int)Math.Round(position.Y), 0, 0); animations = new Animations(spriteSheetInfo); tex = new Texture2D(graphics.GraphicsDevice, animations.spriteSheetInfo.FrameWidth, animations.spriteSheetInfo.FrameHeight); if (!string.IsNullOrEmpty(animations.CurrentAnimationName)) { animations.currentSpriteSheet = animations.spriteSheets.First().Value; } rectangle = new Rectangle((int)Math.Round(position.X), (int)Math.Round(position.Y), tex.Width, tex.Height); origin = new Vector2(tex.Width / 2, tex.Height / 2); }
public SpriteSheet(Texture2D loadedTex, SpriteSheetInfo info, int frameCount, int columns, int rows, Directions direction, long frameTime, bool loop) { tex = loadedTex; this.info = info; this.frameCount = frameCount; this.columns = columns; this.rows = rows; this.direction = direction; this.frameTime = frameTime; this.loop = loop; frameActions = new List <List <Action> >(); for (int i = 0; i < frameCount; i++) { frameActions.Add(new List <Action>()); } }
public Cube(Vector2 origin, Vector3 gridPos, Texture2D southwestTex, Texture2D southeastTex, Texture2D topTex, GraphicsDeviceManager graphics, SpriteSheetInfo spriteSheetInfo) { this.southwestTex = southwestTex; this.southeastTex = southeastTex; this.topTex = topTex; this.origin = origin; this.gridPos = gridPos; this.position = origin + Game1.world.twoDToIso(new Point((int)(gridPos.X * southwestTex.Width), (int)(gridPos.Y * southwestTex.Height * .65f))).ToVector2(); this.position.Y -= gridPos.Z * southwestTex.Height * .65F; this.graphics = graphics; this.spriteSheetInfo = spriteSheetInfo; this.highLight = false; this.invert = false; southwest = new Sprite(southwestTex); southwest.position = position; southwest.position.X -= (int)Math.Floor((double)southwest.tex.Width / 2); // - 1; southwest.position.Y += (int)Math.Floor((double)southwest.tex.Height / 2); // - 1; southwest.origin = new Vector2(southwestTex.Width / 2, southwestTex.Height / 2); southwest.scale = 1f; southwest.rotation = 180; // enables collision by moving the rectangle to the proper space /*southwest.rectangle.X = (int)position.X; * southwest.rectangle.Y = (int)position.Y; * southwest.rectangle.Width = southwest.tex.Width; * southwest.rectangle.Height = southwest.tex.Height;*/ southeast = new Sprite(southeastTex); southeast.position = position; southeast.position.X += (int)Math.Floor((double)southwest.tex.Width / 2); // - 1; southeast.position.Y += (int)Math.Floor((double)southwest.tex.Height / 2); // - 1; southeast.origin = new Vector2(southeastTex.Width / 2, southeastTex.Height / 2); southeast.scale = 1f; southeast.rotation = 180; // enables collision by moving the rectangle to the proper space /*southeast.rectangle.X = (int)position.X; * southeast.rectangle.Y = (int)position.Y; * southeast.rectangle.Width = southeast.tex.Width; * southeast.rectangle.Height = southeast.tex.Height; * southeast.rectangle.*/ top = new Sprite(topTex); top.position = position; top.origin = new Vector2(topTex.Width / 2, topTex.Height / 2); top.scale = 1f; // enables collision by moving the rectangle to the proper space top.rectangle.X = (int)position.X; top.rectangle.Y = (int)position.Y; top.rectangle.Width = top.tex.Width; top.rectangle.Height = top.tex.Height; topPoly = new Polygon(); /*Vector2 topOfDiamond = new Vector2(top.position.X + top.tex.Width / 2 + top.origin.X, top.position.Y + top.origin.Y); * Vector2 bottomOfDiamond = new Vector2(top.position.X + top.tex.Width / 2 + top.origin.X, top.position.Y + top.tex.Height + top.origin.Y); * Vector2 leftOfDiamond = new Vector2(top.position.X + top.origin.X, top.position.Y + top.tex.Height / 2 + top.origin.Y); * Vector2 rightOfDiamond = new Vector2(top.position.X + top.tex.Width + top.origin.X, top.position.Y + top.tex.Height / 2 + top.origin.Y); * topPoly.Lines.Add(new PolyLine(leftOfDiamond, topOfDiamond)); * topPoly.Lines.Add(new PolyLine(topOfDiamond, rightOfDiamond)); * topPoly.Lines.Add(new PolyLine(rightOfDiamond, bottomOfDiamond)); * topPoly.Lines.Add(new PolyLine(bottomOfDiamond, leftOfDiamond));*/ /*if (gridPos == new Vector3(8, 8, 1)) { * Console.WriteLine("Cube Top Rect:" + top.rectangle + " Pos:" + top.position + " Origin:" + top.origin); * }*/ text = new TextItem(World.fontManager["InfoFont"], "X: " + gridPos.X + " Y: " + gridPos.Y + " Z: " + gridPos.Z); text.position = position; /*if (gridPos == new Vector3(8, 8, 1)) * { * // add random transparent colors * rectangleTex = Game1.world.textureConverter.GenRectangle(top.rectangle.Width, top.rectangle.Height, Color.Red); // top.rectangle.Width, top.rectangle.Height, Color.Black); * rectangleSprite = new Sprite(rectangleTex, graphics, spriteSheetInfo); * rectangleSprite.position = new Vector2(top.position.X, top.position.Y); * rectangleSprite.origin = top.origin; * Console.WriteLine("pos:" + rectangleSprite.position); * }*/ /*highlightTex = Game1.world.textureConverter.highlightTex(topTex); * highlight = new Sprite(highlightTex); * highlight.origin = top.origin; * highlight.position = top.position;*/ }
public Sprite(Texture2D baseTex, GraphicsDeviceManager graphics, SpriteSheetInfo spriteSheetInfo) : this(graphics, spriteSheetInfo) { tex = baseTex; }
public Animations(SpriteSheetInfo spriteSheetInfo) { this.spriteSheetInfo = spriteSheetInfo; spriteSheets = new Dictionary <string, SpriteSheet>(); }