public void Update(Direction d) { AnimatedTexture t = textures["right"]; if (d == Direction.RIGHT) { t = textures["right"]; } if (d == Direction.LEFT) { t = textures["left"]; } if (d == Direction.UP) { t = textures["up"]; } if (d == Direction.DOWN) { t = textures["down"]; } t.currentFrame++; if (t.currentFrame == t.totalFrames) { t.currentFrame = 0; } int width = (int)t.texture.Size.X / t.columns; int height = (int)t.texture.Size.Y / t.rows; int row = (int)((float)t.currentFrame / (float)t.columns); int column = t.currentFrame % t.columns; base.Texture = t.texture; base.TextureRect = new IntRect(width * column, height * row, width, height); }
public AnimatedSprite(AnimatedTexture upTexture, AnimatedTexture downTexture, AnimatedTexture rightTexture, AnimatedTexture leftTexture) { textures.Add("right", rightTexture); textures.Add("left", leftTexture); textures.Add("up", upTexture); textures.Add("down", downTexture); }
public AnimatedSprite GetAnimatedSprite(string upTexture, string downTexture, string rightTexture, string leftTexture) { AnimatedTexture up = _animTextures[upTexture]; AnimatedTexture down = _animTextures[downTexture]; AnimatedTexture right = _animTextures[rightTexture]; AnimatedTexture left = _animTextures[leftTexture]; return(new AnimatedSprite(up, down, right, left)); }
public void LoadAnimatedTextureFromFile(string name, string path, int columns, int rows) { AnimatedTexture animTexture = new AnimatedTexture(); animTexture.texture = new Texture(path); animTexture.columns = columns; animTexture.rows = rows; _animTextures.Add(name, animTexture); }