Main
using System;

namespace Libraries
{
    // Purpose:
    // Render system object used to display a image.
    // Draw a sprite/background image.
    public class Sprite : RenderObj
    {
        // Purpose:
        // Rotations.  Rotation is clockwise.
        public enum Rotation
        {
            e_none = 0,
            e_rot90 = 3,
            e_rot180 = 2,
            e_rot270 = 1
        }

        // Purpose:
        // Default constructor.
        public Sprite()
        {
        }

        // Purpose:
        // Constructor.  Setup the properites for the sprite.
        // imageName      - Name of the image to display for the sprite.
        // posX, posY     - Where to display the top left corner of the sprite on the screen.
        // imageX, imageY - Where to render from in the image.  This is the top left corner of the section to draw.  Make it 0, 0 for the top left corner.
        // width, height  - Area in the image to display.  This gets added to imageX, imageY for the area in the image to display.
        // scale          - Scaling to apply when rendering.
        // rotation       - Rotation to apply to the image.
        // show           - Value is true if the sprite should display when rendered, false if not.
        public Sprite(String imageName,
                      int posX, int posY,
                      int imageX, int imageY,
                      int width, int height,
                      int scale,
                      Rotation rotation,
                      bool show)
        {
            m_imageName = imageName;
            m_posX = posX;
            m_posY = posY;
            m_imageX = imageX;
            m_imageY = imageY;
            m_width = width;
            m_height = height;
            m_show = show;
             
            m_scale = scale;
            m_rotation = rotation;
            m_show = show;
        }

        // Purpose:
        // Render the sprite to the given cube.
        public override void Render(Sifteo.Cube cube)
        {
            if(m_show && (null != m_imageName))
                cube.Image(m_imageName, m_posX, m_posY, m_imageX, m_imageY, m_width, m_height, m_scale, (int)m_rotation);  
        }

        // Purpose:
        // Set the image to use.
        public void SetImage(String imageName)
        {
            m_imageName = imageName;
            m_needsRender = true;
        }

        // Purpose:
        // Set the image to use.
        //
        // imageName  - Name of the image to use.
        // needRender - If true, the sprite will be marked as needing a render.
        public void SetImage(String imageName,
                             bool needRender)
        {
            SetImage(imageName);
            if(needRender)
                m_needsRender = true;
        }
       
        // Purpose:
        // Set the position to display the sprite at.
        // x, y - Sprite position.
        public void SetPos(int x, int y)
        {
            m_posX = x;
            m_posY = y;
        }

        // Name of the image to display.
        protected String m_imageName;
       
        // Screen position to display at.  The top left position to start drawing at.
        protected int m_posX = 0;
        protected int m_posY = 0;
 
        // Top left corner in the image to draw from.
        protected int m_imageX = 0;
        protected int m_imageY = 0;
 
        // Dimensions in the image to draw from.
        protected int m_width = 0;
        protected int m_height = 0;
       
        // Scaling to apply when rendering.
        protected int m_scale = 1;

        // Rotation to apply to the image.
        protected Rotation m_rotation = Rotation.e_none;
    }
}

 
Website copyright (c) 2012 Benjamin Millek, all rights reserved.