- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/GraphicalElements/ScrollingText.cs

    00001 ﻿
    00002 namespace NewGamePhysics.GraphicalElements
    00003 {
    00004     using System;
    00005     using System.Text;
    00006     using Microsoft.Xna.Framework;
    00007     using Microsoft.Xna.Framework.Graphics;
    00008
    00013     public class ScrollingText
    00014     {
    00019         private Vector2 scrollerOffset;
    00020
    00024         private float scrollerSpeed;
    00025
    00029         private string text;
    00030
    00034         private int screenWidth;
    00035
    00039         private SpriteFont textFont;
    00040
    00044         private Vector2 textSize;
    00045
    00050         private Color textColor;
    00051
    00056         private float textScale;
    00057
    00062         private static Vector2 textOrigin = new Vector2(0, 0);
    00063
    00071         public ScrollingText(string text, SpriteFont font, int screenWidth, int yPos)
    00072         {
    00073
    00074             this.text = text;
    00075             this.textFont = font;
    00076             this.textSize = this.textFont.MeasureString(text);
    00077
    00078             this.textColor = Color.White;
    00079             this.textScale = 1.0f;
    00080
    00081             // Set x from screen, y from position
    00082             this.screenWidth = screenWidth;
    00083             this.scrollerOffset = new Vector2(this.screenWidth, yPos);
    00084             this.scrollerSpeed = 100.0f;
    00085         }
    00086
    00091         public string Text
    00092         {
    00093             get { return this.text; }
    00094             set {
    00095                 this.text = value;
    00096                 this.textSize = this.textFont.MeasureString(value);
    00097                 this.scrollerOffset = new Vector2(this.screenWidth, this.scrollerOffset.Y);
    00098             }
    00099         }
    00100
    00105         public float ScrollerSpeed
    00106         {
    00107             get { return this.scrollerSpeed; }
    00108             set { this.scrollerSpeed = value; }
    00109         }
    00110
    00115         public Color TextColor
    00116         {
    00117             get { return this.textColor; }
    00118             set { this.textColor = value; }
    00119         }
    00120
    00125         public float TextScale
    00126         {
    00127             get { return this.textScale; }
    00128             set { this.textScale = value; }
    00129         }
    00130
    00134         public void Update(GameTime gameTime)
    00135         {
    00136             // Move scroller
    00137             scrollerOffset.X -= scrollerSpeed * (float)gameTime.ElapsedGameTime.Milliseconds * 0.001f;
    00138
    00139             // Wrap motion
    00140             if (scrollerSpeed > 0.0f)
    00141             {
    00142                 if ((this.scrollerOffset.X + this.textSize.X) < 0)
    00143                 {
    00144                     scrollerOffset.X = this.screenWidth;
    00145                 }
    00146             }
    00147             else
    00148             {
    00149                 if (this.scrollerOffset.X > this.screenWidth)
    00150                 {
    00151                     scrollerOffset.X = -this.textSize.X;
    00152                 }
    00153             }
    00154         }
    00155
    00161         public void Draw(GameTime gameTime, SpriteBatch spriteBatch )
    00162         {
    00163             spriteBatch.Begin();
    00164             spriteBatch.DrawString(
    00165                 this.textFont,
    00166                 this.text,
    00167                 this.scrollerOffset,
    00168                 this.textColor,
    00169                 0,
    00170                 textOrigin,
    00171                 this.textScale,
    00172                 SpriteEffects.None,
    00173                 0);
    00174             spriteBatch.End();
    00175         }
    00176     }
    00177 }