public void AddDrawable(DrawData drawable)
 {
     if (drawable == null || _toDraw.Contains(drawable))
     {
         Console.WriteLine("Unable to add drawable!");
         return;
     }
     _toDraw.Add(drawable);
 }
 /// <summary>
 /// Uses spritebatch to draw the provided element.
 /// Note: Assumes spritebatch.Begin() !
 /// </summary>
 /// <param name="toDraw"></param>
 private void drawElement(DrawData toDraw)
 {
     spriteBatch.Draw(
         toDraw.Art, toDraw.Destination,
         toDraw.Source,toDraw.BlendColor);
 }
Exemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            Texture2D blockArt = Content.Load<Texture2D>("Brown Block");
            _spriteSheet = Content.Load<Texture2D>("spritesheet");

            IDrawSprites renderer = (IDrawSprites)
                                    Services.GetService(typeof (IDrawSprites));
            for (int i = 0; i < 20; i++)
            {
                renderer.AddDrawable(new DrawData(
                    blockArt, new Rectangle(
                        blockArt.Bounds.Width * (i%4), //X
                        (i/4)*blockArt.Bounds.Height / 2, //Y
                        blockArt.Bounds.Width,//Width
                        blockArt.Bounds.Height)));//Height
            }
            _sheet = new DrawData(_spriteSheet);
            _sheet.Source = new Rectangle(0,0,24,32);
            _sheet.Destination = new Rectangle(0,0,24*4,32*4);
            renderer.AddDrawable(_sheet);

               AnimationDrawData animated = new AnimationDrawData(
               _spriteSheet, new Rectangle(0,0, 24, 32),
               new Point(100,100),24*4,32*4,3);
            renderer.AddDrawable(animated);
            _controllers.Add(
                new AnimationController(animated, 0.3f));
        }
 public void RemoveDrawable(DrawData toRemove)
 {
     _toDraw.Remove(toRemove);
 }
        protected virtual void drawElement(DrawData drawable)
        {
            Rectangle worldDestination = drawable.Destination;
            worldDestination.X -= _cameraPosition.X;
            worldDestination.Y -= _cameraPosition.Y;

            _drawer.Draw(drawable.Art, worldDestination,
                drawable.Source, Color.White);
        }
 protected virtual void drawElement(DrawData drawable)
 {
     _drawer.Draw(drawable.Art,drawable.Destination,
         drawable.Source, Color.White);
 }