CoverFlowSelector class

This class creates a 3D rendered "Cover Flow"-style menu. The current item it shown in the forefront, while items to the left and right are shown stacked in the background.

Currently, we've only tested this with 512x512 pixel images, so some tweaking may be required if you use other image sizes.

Constructors

public CoverFlowSelector(float aspectRatio)
Creates a new cover flow interface with the given aspect ratio.

Methods

public void AddCover(Texture2D texture)
Adds a new cover to the list.

public void SetInitialPositions()
Must be called once you have finished adding covers and setting any necessary field or properties. This sets up the initial positioning on all of the covers.

public void Update(GameTime gameTime)
Updates the animations in progress on each cover. You must call this in your game's Update method.

public void Draw(GraphicsDeviceManager graphics, GameTime gameTime)
Draws the cover flow interface to the screen. You must call this in your game's Draw method.

public void MoveLeft()
public void MoveRight()
Scrolls the cover flow one item to the left or right. These methods will automatically prevent you from moving past either the upper or lower bounds of the list, and will also prevent the selection from changing if animations are already in progress.

Fields / Properties

public int SelectedIndex
The currently selected item index.

public int FlowDurationInMilliseconds = 500
The amount of time it takes a cover to spin to or from the front.

public int ShiftDurationInMilliseconds = 100
The amount of time it takes a cover to shift its place in the stack.

public float StackDistance = 0.1f
The distance (X) between items in the stack.

public float StackDepth = 0.1f
The depth (Z) between items in the stack.

public Vector3 SelectedCenter = new Vector3(0, 0, 3)
The position where the selected cover is shown.

public Vector3 LeftStackStart = new Vector3(-1.5f, 0, 0.5f)
The rightmost position in the left stack.

public Vector3 RightStackStart = new Vector3(1.5f, 0, 0.5f)
The leftmost position in the right stack.

public float LeftStackAngle = MathHelper.ToRadians(70)
The angle at which items in the left stack are shown.

public float RightStackAngle = MathHelper.ToRadians(-70)
The angle at which items in the right stack are shown.

Example usage

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    CoverFlowSelector coverflow;
    List<Controller> controllers;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        coverflow = new CoverFlowSelector(graphics.PreferredBackBufferWidth / (float)graphics.PreferredBackBufferHeight);
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));
        coverflow.AddCover(Content.Load<Texture2D>("Board1_Cover"));

        coverflow.LeftStackStart.X = -1;
        coverflow.RightStackStart.X = 1;

        coverflow.SetInitialPositions();

        controllers = new List<Controller>();
        controllers.Add(new Controller(PlayerIndex.One));
        controllers.Add(new Controller(PlayerIndex.Two));
        controllers.Add(new Controller(PlayerIndex.Three));
        controllers.Add(new Controller(PlayerIndex.Four));
    }

    protected override void Update(GameTime gameTime)
    {
        foreach (Controller c in controllers)
        {
            c.Update(gameTime);
            if (c.ButtonReleased[Buttons.DPadLeft]) { coverflow.MoveLeft(); }
            if (c.ButtonReleased[Buttons.DPadRight]) { coverflow.MoveRight(); }
            if (c.ButtonReleased[Buttons.Back]) { Exit(); }
        }

        coverflow.Update(gameTime);

        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        coverflow.Draw(graphics, gameTime);

        base.Draw(gameTime);
    }
}

Last edited Jan 4, 2010 at 2:48 AM by dylanwolf, version 2

Comments

No comments yet.