Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualLordRhys

Posted 04 February 2013 - 11:13 AM

 I used a technique that was in an XNA TileEngine tutorial by Nick Gravelyn where a renderlist is created and a sort done based on a comparison between object origins. This all works great between the animated sprites (player, npc's, and mobs) however my issue is with the player and non-animated objects like treasure chests and other items that may be placed. The code pieces I use are listed below, I am trying to figure out how I would also include the BaseSprite class objects. This is done so that when the player passes an npc, mob or object atthe top of that sprite he will be displayed as walking behind it.

 

private List<AnimatedSprite> renderList = new List<AnimatedSprite>();
 

    private Comparison<AnimatedSprite> renderSort =
      new Comparison<AnimatedSprite>(renderSpriteComapre);
   
    // also have BaseSprite chestSprite as non-animated sprite object

    BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point((int)c.Value.X, (int)c.Value.Y));
   
    renderList.Add(npc.Sprite);
    renderList.Add(mob.Sprite);
    renderList.Add(player.Sprite);
   
    private static int renderSpriteComapre(AnimatedSprite a, AnimatedSprite b)
    {
        return a.Origin.Y.CompareTo(b.Origin.Y);
    }   
   
    public override void Draw(GameTime gameTime)
    {
      //spritebatch.begin info
      //draw level code
     
      renderList.Sort(renderSort);


 

      foreach (AnimatedSprite s in renderList)
        s.Draw(gameTime, GameRef.SpriteBatch);
     
      //spritebatch.end info     
    }
    


#1LordRhys

Posted 04 February 2013 - 11:11 AM

 I used a technique that was in an XNA TileEngine tutorial by Nick Gravelyn where a renderlist is created and a sort done based on a comparison between object origins. This all works great between the animated sprites (player, npc's, and mobs) however my issue is with the player and non-animated objects like treasure chests and other items that may be placed. The code pieces I use are listed below, I am trying to figure out how I would also include the BaseSprite class objects.

 

private List<AnimatedSprite> renderList = new List<AnimatedSprite>();
 

    private Comparison<AnimatedSprite> renderSort =
      new Comparison<AnimatedSprite>(renderSpriteComapre);
   
    // also have BaseSprite chestSprite as non-animated sprite object

    BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point((int)c.Value.X, (int)c.Value.Y));
   
    renderList.Add(npc.Sprite);
    renderList.Add(mob.Sprite);
    renderList.Add(player.Sprite);
   
    private static int renderSpriteComapre(AnimatedSprite a, AnimatedSprite b)
    {
        return a.Origin.Y.CompareTo(b.Origin.Y);
    }   
   
    public override void Draw(GameTime gameTime)
    {
      //spritebatch.begin info
      //draw level code
     
      renderList.Sort(renderSort);


 

      foreach (AnimatedSprite s in renderList)
        s.Draw(gameTime, GameRef.SpriteBatch);
     
      //spritebatch.end info     
    }
    


PARTNERS