animaceTextu
Game1:
...
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
AnimaceText AnimaceText;
SpriteFont pismo;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
...
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
pismo = Content.Load("Pismo");
//argumenty spriteFont,pruhlednost,rychlost(vertikál,horihontál),,scale,otáčení negativ(1-jen positiv 2-i negativ vyšší číslo počet opakování
// mezera Vertikální,mezrra Horizontální,rotace
AnimaceText = new AnimaceText(pismo,1,new Vector2(0.003f,0.003f),new Vector2(5,5),2,100,100,0.003f);
// argumenty pozice,text1,text2
AnimaceText.nacteni( new Vector2(300, 100),"123","abcde");
// TODO: use this.Content to load your game content here
}
...
protected override void Update(GameTime gameTime)
{
> // Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
> // TODO: Add your update logic here
AnimaceText.update(gameTime);
base.Update(gameTime);
}
...
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
AnimaceText.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Třída animaceTextu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AnimaceTextu
{
class AnimaceText
{
List AnimaceTextUkaz = new List();
private float pruhlednost = 1,rotace,rotaceUkaz;
private int mezeraVer, mezeraHor, positiv = 1;
private SpriteFont pismo;
private string pismeno, pismeno1, pismeno2;
private Vector2 smer, pomoc, citac, scale, pozice, rychlost;
public AnimaceText(SpriteFont pismo, float pru, Vector2 rych, Vector2 sca, int pos, int mezeraVer, int mezeraHor,float rotace)
{
this.pismo = pismo;
this.pruhlednost = pru;
this.rychlost = rych;
this.positiv = pos;
this.mezeraVer = mezeraVer;
this.mezeraHor = mezeraHor;
this.scale = sca;
smer = new Vector2(1, 1);
pomoc = new Vector2(1, 1);
this.rotace = rotace;
}
public void update(GameTime gameTime)
{
float elapsed = (float)gameTime.ElapsedGameTime.TotalMilliseconds;
for (int i = 0; i < AnimaceTextUkaz.Count; i++)
{
AnimaceTextUkaz[i].scale.X += elapsed * rychlost.X * AnimaceTextUkaz[i].smer.X;
if (AnimaceTextUkaz[i].scale.X > scale.X)
AnimaceTextUkaz[i].smer.X = -1;
if (AnimaceTextUkaz[i].scale.X < 0)
{
AnimaceTextUkaz[i].smer.X = 1;
if (positiv == 2)
AnimaceTextUkaz[i].pomoc.X *= -1;
AnimaceTextUkaz[i].citac.X++;
if (AnimaceTextUkaz[i].citac.X == positiv)
{
if (AnimaceTextUkaz[i].pismeno == AnimaceTextUkaz[i].pismeno1)
AnimaceTextUkaz[i].pismeno = AnimaceTextUkaz[i].pismeno2;
else
{
AnimaceTextUkaz[i].pismeno = AnimaceTextUkaz[i].pismeno1;
}
AnimaceTextUkaz[i].citac.X = 0;
}
}
AnimaceTextUkaz[i].scale.Y += elapsed * rychlost.Y * AnimaceTextUkaz[i].smer.Y;
if (AnimaceTextUkaz[i].scale.Y > scale.Y)
AnimaceTextUkaz[i].smer.Y = -1;
if (AnimaceTextUkaz[i].scale.Y < 0)
{
AnimaceTextUkaz[i].smer.Y = 1;
if (positiv == 2)
AnimaceTextUkaz[i].pomoc.Y *= -1;
AnimaceTextUkaz[i].citac.Y++;
if (AnimaceTextUkaz[i].citac.Y == positiv)
{
if (rychlost.X == 0)
if (AnimaceTextUkaz[i].pismeno == AnimaceTextUkaz[i].pismeno1)
AnimaceTextUkaz[i].pismeno = AnimaceTextUkaz[i].pismeno2;
else
{
AnimaceTextUkaz[i].pismeno = AnimaceTextUkaz[i].pismeno1;
}
AnimaceTextUkaz[i].citac.Y = 0;
}
}
}
rotaceUkaz += elapsed * rotace % MathHelper.TwoPi;
}
public void Draw(SpriteBatch spriteBatch)
{
for (int i = 0; i < AnimaceTextUkaz.Count; i++)
{
Vector2 pismeno = pismo.MeasureString(AnimaceTextUkaz[i].pismeno);
if (AnimaceTextUkaz[i].pomoc.X == 1 && AnimaceTextUkaz[i].pomoc.Y == 1)
{
spriteBatch.DrawString(pismo, AnimaceTextUkaz[i].pismeno, new Vector2(AnimaceTextUkaz[i].pozice.X + i * mezeraHor, AnimaceTextUkaz[i].pozice.Y + i * mezeraVer), Color.Teal * pruhlednost, rotaceUkaz, new Vector2(pismeno.X / 2, pismeno.Y / 2), AnimaceTextUkaz[i].scale, SpriteEffects.None, 0);
}
else
{
if (AnimaceTextUkaz[i].pomoc.Y != 2)
spriteBatch.DrawString(pismo, AnimaceTextUkaz[i].pismeno, new Vector2(AnimaceTextUkaz[i].pozice.X + i * mezeraHor, AnimaceTextUkaz[i].pozice.Y + i * mezeraVer), Color.Teal * pruhlednost, rotaceUkaz, new Vector2(pismeno.X / 2, pismeno.Y / 2), AnimaceTextUkaz[i].scale, SpriteEffects.FlipVertically, 0);
else
{
spriteBatch.DrawString(pismo, AnimaceTextUkaz[i].pismeno, new Vector2(AnimaceTextUkaz[i].pozice.X + i * mezeraHor, AnimaceTextUkaz[i].pozice.Y + i * mezeraVer), Color.Teal * pruhlednost, rotaceUkaz, new Vector2(pismeno.X / 2, pismeno.Y / 2), AnimaceTextUkaz[i].scale, SpriteEffects.FlipHorizontally, 0);
}
}
}
}
public void nacteni(Vector2 poz, string txt, string txt1)
{
int cyklus;
float sscaleX, sscaleY;
if (txt.Length >= txt1.Length)
{
cyklus = txt.Length;
sscaleX = scale.X / txt.Length;
sscaleY = scale.Y / txt.Length;
}
else
{
cyklus = txt1.Length;
sscaleX = scale.X / txt1.Length;
sscaleY = scale.Y / txt1.Length;
}
if (rychlost.X == 0)
sscaleX = 0;
if (rychlost.Y == 0)
sscaleY = 0;
for (int i = 0; i < cyklus; i++)
{
AnimaceText s = new AnimaceText(pismo, pruhlednost, rychlost, scale, positiv, mezeraVer, mezeraHor,rotace);
s.pozice = poz;
s.pismeno = "";
s.pismeno1 = "";
s.pismeno2 = "";
if (txt.Length >= i + 1)
{
s.pismeno = txt[i].ToString();
s.pismeno1 = txt[i].ToString();
}
if (txt1.Length >= i + 1)
s.pismeno2 = txt1[i].ToString();
s.scale.X = scale.X - sscaleX * i - sscaleX;
s.scale.Y = scale.Y - sscaleY * i - sscaleY;
AnimaceTextUkaz.Add(s);
}
}
}
}