Na FreeHostingu Endora běží desítky tisíc webů. Přidejte se ještě dnes!

Vytvořit web zdarma

Na FreeHostingu Endora běží desítky tisíc webů. Přidejte se ještě dnes!

Vytvořit web zdarma
Úvod HTML CSS PHP MySQL JavaScript
scrolltextu

Scroll textu z txt souboru

Vytvoříme soubor pravým na projekt Robotris v Solution Exploreru -> Add -> New Item -> Text File . Souboru v okně Properties nastavit Copy to Output Directory na Copy always. Visual Studio bude tento soubor přidávat do složky s zkompilovanou hrou.
      using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.IO;


namespace UvodHry.komponenty
{
  
    public class Autori : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game1 game1;

        private string text;
        private Vector2 startovniPozice;
        public Vector2 pozice;
        private float vyskaTextu;
        private SpriteFont font;


        public Autori(Game1 game1)
            : base(game1)
        {
          
            this.game1 = game1;
        }

    
        public override void Initialize()
        {
           



            base.Initialize();
        }


        protected override void LoadContent()
        {
            NactiText();
            startovniPozice = new Vector2(310, 550);
            pozice = startovniPozice;

            font = game1.Content.Load(@"menufont");
            vyskaTextu = font.MeasureString(text).Y;
            base.LoadContent();
        }
      
        public override void Update(GameTime gameTime)
        {
          
            double elapsed = gameTime.ElapsedGameTime.TotalMilliseconds;


            if (game1.Input.PraveTlacitkoStisknuto() || game1.Input.StisknutaKlavesa(Keys.Escape))
            {
                this.Enabled = false;
                this.Visible = false;
            }
            pozice.Y -= 0.08F * (float)elapsed;

            if (pozice.Y < startovniPozice.Y - (vyskaTextu + 320))
                pozice = startovniPozice;

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {

            // vyklreslení skrolujícího textu pomocí clippingu (nůžek):
            // zapnutí clippingu    
            RasterizerState rs = new RasterizerState();
            rs.ScissorTestEnable = true;
            game1.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, rs);
              // uložení současných nůžek    
            Rectangle currentRect = game1.spriteBatch.GraphicsDevice.ScissorRectangle;
              // nastavení nůžek           
            game1.spriteBatch.GraphicsDevice.ScissorRectangle = new Rectangle(310, 240, 700, 335);
              // vykreslení textu       
            game1.spriteBatch.DrawString(font, text, pozice, Color.Red);
              // reset původních nůžek    
            game1.spriteBatch.GraphicsDevice.ScissorRectangle = currentRect;
            game1.spriteBatch.End();

            base.Draw(gameTime);
        }


        public void NactiText()
        {
            text = "";
            using (StreamReader sr = new StreamReader("autori.txt"))
            {
                text = sr.ReadToEnd();
            }
        }
    }
}

 
 
    
pravy Ascii tabulka
Barvy
Klávesové zkratky


©2013-2021 Trojklik.8u.cz Autor: Vašek D.