/// <summary> /// Affichage avec flip /// </summary> /// <param name="screen"></param> /// <param name="x"></param> /// <param name="y"></param> public void Draw(SurfaceSprite screen, int x, int y, bool isHorizontalFlipped, bool isVerticalFlipped) { if (State != AnimatorStates.Stop) { CurrentAnimationFrame.Draw(screen, x, y, isHorizontalFlipped, isVerticalFlipped); } }
/// <summary> /// Affichage sans flip /// </summary> /// <param name="screen"></param> /// <param name="x"></param> /// <param name="y"></param> public void Draw(SurfaceSprite screen, int x, int y) { if (State != AnimatorStates.Stop) { CurrentAnimationFrame.Draw(screen, x, y); } }
public override void Draw(SurfaceSprite screen, int x, int y, bool isHorizontalFlipped, bool isVerticalFlipped) { // si isHorizontalFlipped alors on inverse la valeur IsHorizontalFlipped stocké dans la frame isHorizontalFlipped = isHorizontalFlipped == true ? !IsHorizontalFlipped : IsHorizontalFlipped; isVerticalFlipped = isVerticalFlipped == true ? !IsVerticalFlipped : IsVerticalFlipped; screen.DrawSpriteMap(Map, x + RelativeX, y + RelativeY, isHorizontalFlipped, isVerticalFlipped); }
public SurfaceSprite CreateEmptySprite(string name, int width, int height) { var sprite = new SurfaceSprite(); var address = this.ReserveEmptySprite(sprite, name, width, height); sprite.Initialize(this.Pixels, address, width, height); return(sprite); }
/// <summary> /// Creer un sprite vide /// </summary> /// <returns></returns> private int ReserveEmptySprite(SurfaceSprite sprite, string name, int width, int height) { var address = this.CurrentAddress; this.sprites.Add(name, sprite); // on ne peut pas se servire de sprite.Size car le sprite n'est pas encore initialisé int size = width * height; this.CurrentAddress += size; return(address); }
public void DrawCollisionBox(SurfaceSprite screen, bool checkCanCollide = true) { if (checkCanCollide) { if (CanCollide) { screen.DrawRectangle(XScrolled + this.CollisionBounds.X, YScrolled + this.CollisionBounds.Y, this.CollisionBounds.Width, this.CollisionBounds.Height, Argb32.Magenta, false); } } else { screen.DrawRectangle(XScrolled + this.CollisionBounds.X, YScrolled + this.CollisionBounds.Y, this.CollisionBounds.Width, this.CollisionBounds.Height, Argb32.Magenta, false); } }
public void DrawSprite(SurfaceSprite surface, int xScreen, int yScreen, bool isHorizontalFlipped, bool isVerticalFlipped, int xSprite = 0, int ySprite = 0, int widthSprite = int.MaxValue, int heightSprite = int.MaxValue) { if (widthSprite == int.MaxValue) { widthSprite = surface.Width; } if (heightSprite == int.MaxValue) { heightSprite = surface.Height; } if (this.BoundsClipped.Width <= 0 || this.BoundsClipped.Height <= 0) { return; } SurfaceRectangle rectScreen = new SurfaceRectangle(); int destinationAddress = 0; int sourceAddress = 0; // pas de clipping: La destination ne bouge pas (sauf exception des xscreen/yScreen negatif et la source bouge if (HaveClip == false) { // La lecture des pixels commence en négatif (en gros on devrait afficher du transparent) // Pour afficher ces pixels qui n'existent pas on compense en poussant la position à l'écran et en diminuant la taille if (ySprite < 0) { yScreen += -ySprite; heightSprite += ySprite; ySprite = 0; } if (xSprite < 0) { xScreen += -xSprite; widthSprite += xSprite; xSprite = 0; } // on genere le rectangle affichable de la source. Il prend en compte son clipping à lui (souvent inutile) mais pas celui de l'ecran. var rectSprite = surface.GetVisibleRectangle(xSprite, ySprite, widthSprite, heightSprite, false, false); if (rectSprite.isVisible == false) { return; } // on genere le rectangle affichable de l'ecran en prenant la taille de celui du rectangle de la source rectScreen = this.GetVisibleRectangle(xScreen, yScreen, rectSprite.width, rectSprite.height, isHorizontalFlipped, isVerticalFlipped); if (rectScreen.isVisible == false) { return; } sourceAddress = rectSprite.address; // On sort de l'ecran mais le rectangle est visible donc on recalcule l'adresse de départ en ajoutant les lignes perdues if (yScreen < 0) { if (isVerticalFlipped == false) { sourceAddress += (surface.Width * -yScreen); } else { if (heightSprite > BoundsClipped.Height) // cas ou la taille affichable est plus petite que le sprite et que l'on est flipH { var sourceOffsetY = ((yScreen + heightSprite) - BoundsClipped.Height); if (sourceOffsetY >= 0) { sourceAddress += surface.Width * sourceOffsetY; } } // on avance la source du nombre de pixel caché par le bord de l'ecran } } else if (yScreen + heightSprite >= BoundsClipped.Height) { if (isVerticalFlipped == true) { var sourceOffsetY = ((yScreen + heightSprite) - BoundsClipped.Height); sourceAddress += surface.Width * sourceOffsetY; // on avance la source du nombre de pixel caché par le bord de l'ecran } } if (xScreen < 0) { if (isHorizontalFlipped == false) { sourceAddress += -xScreen; // on avance la source du nombre de pixel caché par le bord de l'ecran } else { if (widthSprite > BoundsClipped.Width) // cas ou la taille affichable est plus petite que le sprite et que l'on est flipH { var sourceOffsetX = ((xScreen + widthSprite) - BoundsClipped.Width); if (sourceOffsetX >= 0) { sourceAddress += sourceOffsetX; } } // on avance la source du nombre de pixel caché par le bord de l'ecran } // en mode flip Horizontal on a pas besoin d'avancer car la source address et la derniere pixel de la ligne } else if (xScreen + widthSprite >= this.BoundsClipped.Width) { if (isHorizontalFlipped == true) { var sourceOffsetX = ((xScreen + widthSprite) - BoundsClipped.Width); sourceAddress += sourceOffsetX; // on avance la source du nombre de pixel caché par le bord de l'ecran } } destinationAddress = rectScreen.address; } // ** Gestion du clipping : ici le mouvement se fait du coté de la source et la destination (écran) reste fixe ** else { // on genere le rectangle affichable de la source (il prend en compte son clipping à lui (souvent inutile) et le clipping de l'écran mais qui bouge en xscreen et yscreen ) var sourceClipped = new Rectangle(this.BoundsClipped.X - xScreen + xSprite, this.BoundsClipped.Y - yScreen + ySprite, this.BoundsClipped.Width, this.BoundsClipped.Height); var rectSprite = surface.GetVisibleRectangle(xSprite, ySprite, widthSprite, heightSprite, false, false, sourceClipped); if (rectSprite.isVisible == false) { return; } // on genere le rectangle affichable de l'ecran en prenant la taille de celui du rectangle de la source rectScreen = this.GetVisibleRectangle(this.BoundsClipped.X, this.BoundsClipped.Y, rectSprite.width, rectSprite.height, isHorizontalFlipped, isVerticalFlipped); if (rectScreen.isVisible == false) { return; } sourceAddress = rectSprite.address; destinationAddress = rectScreen.address; // compensation sur la destinationAddress if (isHorizontalFlipped == false) { //if (rectSprite.x == 0) //{ if (xScreen + widthSprite > BoundsClipped.Right) { destinationAddress += (this.BoundsClipped.Width - rectSprite.width); } else if (xScreen > BoundsClipped.X) { destinationAddress += xScreen - BoundsClipped.X; } //} } else { if (rectSprite.x == xSprite) { if (xScreen + widthSprite > BoundsClipped.Right) { sourceAddress += ((xScreen + widthSprite) - this.BoundsClipped.Right); destinationAddress += (this.BoundsClipped.Width - rectSprite.width); } else if (xScreen > BoundsClipped.X) { destinationAddress += xScreen - BoundsClipped.X; } } else { if (xScreen < BoundsClipped.X) { if (xScreen + widthSprite > BoundsClipped.Right) { // fn de ligne - distance entre xScreen et le x de la zone de clipping sourceAddress += ((xScreen + widthSprite) - this.BoundsClipped.Right) - (BoundsClipped.X - xScreen); } else { sourceAddress += -rectSprite.x + xSprite; } } } } // Vertical if (isVerticalFlipped == false) { //if (rectSprite.y == 0) //{ if (yScreen + heightSprite > BoundsClipped.Bottom) { destinationAddress += (this.BoundsClipped.Height - rectSprite.height) * this.Width; } else if (yScreen > BoundsClipped.Y) { destinationAddress += (yScreen - BoundsClipped.Y) * this.Width; } //} } else { if (rectSprite.y == ySprite) { if (yScreen + heightSprite > BoundsClipped.Bottom) { sourceAddress += ((yScreen + heightSprite) - this.BoundsClipped.Bottom) * surface.Width; destinationAddress += (this.BoundsClipped.Height - rectSprite.height) * this.Width; } else if (yScreen > BoundsClipped.Y) { destinationAddress += (yScreen - BoundsClipped.Y) * this.Width; } } else { if (yScreen < BoundsClipped.Y) { // Peut-on virer ce if ? et laisser seulement le else // s'il n'arrive jamais dans le point d'arret c'est le cas if (yScreen + heightSprite > BoundsClipped.Bottom) { // fn de ligne - distance entre xScreen et le x de la zone de clipping sourceAddress += (((yScreen + heightSprite) - this.BoundsClipped.Bottom) - (BoundsClipped.Y - yScreen)) * surface.Width; } else { sourceAddress += (-rectSprite.y + ySprite) * surface.Width; } } } } } // Affichage var strideDestination = rectScreen.stride; var strideSource = surface.Width - Math.Min(surface.Width, rectScreen.width); var heightScreen = rectScreen.height; var widthScreen = rectScreen.width; var destinationPixels = this.Pixels; var sourcePixels = surface.Pixels; int destinationDirection = rectScreen.direction; //try //{ for (int iy = 0; iy < heightScreen; iy++) { for (int ix = 0; ix < widthScreen; ix++) { destinationPixels[destinationAddress].AlphaBlend(sourcePixels[sourceAddress], this.Opacity); // sinon c'est invisible sourceAddress++; destinationAddress += destinationDirection; } destinationAddress += strideDestination; sourceAddress += strideSource; } //} //catch (Exception ex) //{ //} //if (HaveClip) //{ // // test : En Green affiche la source qui sera envoyé à destination // DrawRectangle(rectScreen.x, rectScreen.y, rectScreen.width, rectScreen.height, Argb32.Green, false); //} }
public void DrawSprite(SurfaceSprite surface, int xScreen, int yScreen) { this.DrawSprite(surface, xScreen, yScreen, false, false); }
/// <summary> /// Draw /// </summary> public override void Draw(SurfaceSprite screen, int x, int y) { screen.DrawSpriteMap(Map, x + RelativeX, y + RelativeY, IsHorizontalFlipped, IsVerticalFlipped); }
/// <summary> /// Draw /// </summary> public override void Draw(SurfaceSprite screen, int x, int y) { screen.DrawTile(Tiles, TileNumber, x + RelativeX, y + RelativeY, IsHorizontalFlipped, IsVerticalFlipped); }
public abstract void Draw(SurfaceSprite screen, int x, int y, bool isHorizontalFlipped, bool isVerticalFlipped);
public abstract void Draw(SurfaceSprite screen, int x, int y);
/// <summary> /// Constructeur /// </summary> /// <param name="frameCount"></param> /// <param name="relativeX"></param> /// <param name="relativeY"></param> public SpriteAnimationFrame(SurfaceSprite sprite, int frameCount, bool isHorizontalFlipped = false, bool isVerticalFlipped = false, int relativeX = 0, int relativeY = 0) : base(frameCount, isHorizontalFlipped, isVerticalFlipped, relativeX, relativeY) { this.Sprite = sprite; }