Inheritance: MonoBehaviour
        /// <summary>
        /// Registers the font with the specified name.
        /// </summary>
        /// <param name="name">The name of the font to register.</param>
        /// <param name="font">The font to register.</param>
        public void RegisterFont(String name, SpriteFont font)
        {
            Contract.RequireNotEmpty(name, "name");
            Contract.Require(font, "font");

            registeredFonts.Add(name, font);
        }
    public static void LoadContent(MainGame game)
    {
        // Load assets
        player = game.Content.Load<Texture2D>("player");
        gun = game.Content.Load<Texture2D>("gun");
        dot = game.Content.Load<Texture2D>("dot");
        create = game.Content.Load<Texture2D>("create");
        bullet = game.Content.Load<Texture2D>("bullet");
        aim = game.Content.Load<Texture2D>("aim");
        font = game.Content.Load<SpriteFont>("spriteFont");

        // Init tiles 
        tileTable.Put('O', new TileData(ETileType.FLOOR, dot, Color.DarkGray));
        tileTable.Put('W', new TileData(ETileType.WALL, dot, Color.Black));
        tileTable.Put('S', new TileData(ETileType.SPAWN, dot, Color.Red));
        tileTable.Put('C', new TileData(ETileType.CRATE, create, Color.Brown));


        // Init key bindings
        inputTable.Put(Player.Commands.MoveUp, new LinkedList<Keys>() { Keys.Up, Keys.W });
        inputTable.Put(Player.Commands.MoveDown, new LinkedList<Keys>() { Keys.Down, Keys.S });
        inputTable.Put(Player.Commands.MoveLeft, new LinkedList<Keys>() { Keys.Left, Keys.A });
        inputTable.Put(Player.Commands.MoveRight, new LinkedList<Keys>() { Keys.Right, Keys.D });


        loadMap(game);
    }
Beispiel #3
0
 public Button(Texture2D texture, SpriteFont font, SpriteBatch sBatch)
 {
     image = texture;
     this.font = font;
     location = new Rectangle(0, 0, image.Width, image.Height);
     spriteBatch = sBatch;
 }
 public DrawStringCall(SpriteFont font, string value, Vector2 position, Vector4 color)
 {
     this.font = font;
     this.value = value;
     this.position = position;
     this.color = color;
 }
Beispiel #5
0
    public GameWorld(int width, int height, ContentManager Content)
    {
        screenWidth = width;
        screenHeight = height;
        random = new Random();
        gameState = GameState.Menu;
        inputHelper = new InputHelper();
        block = Content.Load<Texture2D>("block");
        reset = Content.Load<Texture2D>("reset");
        font = Content.Load<SpriteFont>("SpelFont");
        font2 = Content.Load<SpriteFont>("SpriteFont1");
        font3 = Content.Load<SpriteFont>("SpriteFont2");
        playButton = Content.Load<Texture2D>("Play");
        optionsButton = Content.Load<Texture2D>("Options");
        backButton = Content.Load<Texture2D>("Back");
        polytris = Content.Load<Texture2D>("Polytris");
        grid = new TetrisGrid(block);
        level = 1;
        levelspeed = 1;
        score = 0;
        i = (int)random.Next(7) + 1;
        i2 = (int)random.Next(7) + 1;
        blockcounter = 1;

        blocks = new BlockList(block, Content);          //Voegen de verschillende blockobjecten toe aan de lijst
        block1 = new Block1(block, Content);
        blocks.Add(block1, 1);
        block2 = new Block2(block, Content);
        blocks.Add(block2, 2);
        block3 = new Block3(block, Content);
        blocks.Add(block3, 3);
        block4 = new Block4(block, Content);
        blocks.Add(block4, 4);
        block5 = new Block5(block, Content);
        blocks.Add(block5, 5);
        block6 = new Block6(block, Content);
        blocks.Add(block6, 6);
        block7 = new Block7(block, Content);
        blocks.Add(block7, 7);

        //Voegen de verschillende blockobjecten toe aan een tweede lijst voor het tekenen van het volgende blokje
        block1res = new Block1(block, Content);
        blocks.AddToReserve(block1res, 1);
        block2res = new Block2(block, Content);
        blocks.AddToReserve(block2res, 2);
        block3res = new Block3(block, Content);
        blocks.AddToReserve(block3res, 3);
        block4res = new Block4(block, Content);
        blocks.AddToReserve(block4res, 4);
        block5res = new Block5(block, Content);
        blocks.AddToReserve(block5res, 5);
        block6res = new Block6(block, Content);
        blocks.AddToReserve(block6res, 6);
        block7res = new Block7(block, Content);
        blocks.AddToReserve(block7res, 7);

        options = new Options(block, reset, backButton, width, height, font, blocks);
        menu = new Menu(playButton, optionsButton, polytris, width, height);
        gameOver = new GameOver(backButton, width, height);
    }
 /// <summary>Create a new text object.</summary>
 /// <param name="assetname">The name of the sprite font to use.</param>
 /// <param name="layer">The layer to draw the text in.</param>
 /// <param name="id">The reference ID for this text object.</param>
 public TextGameObject(string assetname, int layer = 0, string id = "") : base(layer, id)
 {
     spriteFont = GameEnvironment.AssetManager.Content.Load<SpriteFont>(assetname);
     color = Color.White;
     text = "";
     centered = false;
 }
        protected  Entity GetUIEntity(SpriteFont font, bool fixedSize, Vector3 position)
        {
            // Create and initialize "Touch Screen to Start"
            var touchStartLabel = new ContentDecorator
            {
                Content = new TextBlock
                {
                    Font = font,
                    TextSize = 32,
                    Text = (fixedSize) ? "Fixed Size UI" : "Regular UI",
                    TextColor = Color.White
                },
                Padding = new Thickness(30, 20, 30, 25),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            //touchStartLabel.SetPanelZIndex(1);

            var grid = new Grid
            {
                BackgroundColor = (fixedSize) ? new Color(255, 0, 255) : new Color(255, 255, 0),
                MaximumWidth = 100,
                MaximumHeight = 100,
                MinimumWidth = 100,
                MinimumHeight = 100,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition());
            grid.LayerDefinitions.Add(new StripDefinition());

            grid.Children.Add(touchStartLabel);

            // Add the background
            var background = new ImageElement { StretchType = StretchType.Fill };
            background.SetPanelZIndex(-1);

            var uiEntity = new Entity();

            // Create a procedural model with a diffuse material
            var uiComponent = new UIComponent
            {
                Page = new UIPage
                {
                    RootElement = new UniformGrid { Children = { background, grid } }
                },
                //IsBillboard = true,
                IsFixedSize = fixedSize,
                IsFullScreen = false,
                Resolution = new Vector3(100, 100, 100), // Same size as the inner grid
                Size = new Vector3(0.1f), // 10% of the vertical resolution
            };
            uiEntity.Add(uiComponent);

            uiEntity.Transform.Position = position;

            return uiEntity;
        }
 public int FontHeight(SpriteFont font, String text)
 {
     //to get the text exactly in the middle of the screen
     int fontHeight;
     fontHeight = (int)font.MeasureString(text).Y;
     return fontHeight;
 }
	// Adds a font to our list:
	static void AddFont(SpriteFont f)
	{
		SpriteFont[] newFonts = new SpriteFont[fonts.Length + 1];
		fonts.CopyTo(newFonts, 0);
		newFonts[fonts.Length] = f;
		fonts = newFonts;
	}
 public int FontWidth(SpriteFont font, String text)
 {
     //to get the text exactly in the middle of the screen
     int fontWidth;
     fontWidth = (int)font.MeasureString(text).X;
     return fontWidth;
 }
    public GameWorld(int width, int height, ContentManager Content)
    {
        screenWidth = width;
        screenHeight = height;
        gameState = GameState.StartScreen;

        StartScreenFont = Content.Load<SpriteFont>("Fipps");
    }
Beispiel #12
0
 public TextStyle(SpriteFont font, Boolean? bold, Boolean? italic, Color? color, params GlyphShader[] glyphShaders)
 {
     this.Font = font;
     this.Bold = bold;
     this.Italic = italic;
     this.Color = color;
     this.GlyphShaders = new TextStyleGlyphShaderCollection(glyphShaders);
 }
Beispiel #13
0
 public Text(string Filename, string Text, Vector2 Position)
 {
     if (Filename == "") { Filename = "SpriteFont1"; }
     fontName = Filename;
     font = Cache.Font(Filename);
     position = Position;
     content = Text;
 }
Beispiel #14
0
 protected override void LoadContent()
 {
     //BGM�̎擾�@���Ǘ\��
     song[0] = Content.Load<Song>("Content/GLORIA");
     font = Content.Load<SpriteFont>("Content/MS20");
     sprite = new SpriteBatch(GraphicsDevice);
     ios = new IOS(Gm.GraphicsDevice, sprite,font ,song ,"Hoge.txt");
     base.LoadContent();
 }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            hanSans13 = Content.Load<SpriteFont>(AssetPrefix + "HanSans13");
            hanSans18 = Content.Load<SpriteFont>(AssetPrefix + "HanSans18");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
 /// <summary>
 /// Print a custom overlay message
 /// </summary>
 /// <param name="message"></param>
 /// <param name="position"></param>
 /// <param name="color"></param>
 /// <param name="font"></param>
 public void Print(string message, Vector2 position, Color4 color, SpriteFont font)
 {
     var msg = new DebugOverlayMessage { Message = message, Position = position, TextColor = color, TextFont = font };
     overlayMessages.Enqueue(msg);
     //drop one old message if the tail size has been reached
     if (overlayMessages.Count > TailSize)
     {
         overlayMessages.Dequeue();
     }
 }
Beispiel #17
0
 private static float GetWidth(SpriteFont font, string word)
 {
     float width = 0.0f;
     int length = word[word.Length - 1] == ' ' ? word.Length - 1 : word.Length;
     for (int index = 0; index < length; index++)
     {
         width += GetWidth(font, word[index]);
     }
     return width;
 }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            msMincho10 = Content.Load<SpriteFont>(AssetPrefix + "MSMincho10");
            arialMS = Content.Load<SpriteFont>(AssetPrefix + "Meiryo14");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
Beispiel #19
0
 public Paddle(Vector2 position, Vector2 fontPosition, string texture, float multiplier, Keys kUp, Keys kDown)
     : base(texture, position)
 {
     this.kUp = kUp;
     this.kDown = kDown;
     this.multiplier = multiplier;
     this.fontPosition = fontPosition;
     this.score = 98;
     font = AssetHandler.GetSpriteFont("SpriteFont1");
 }
Beispiel #20
0
 public override void LoadContent()
 {
     texture = ScreenManager.Game.Content.Load<Texture2D>("GameOverScreen");
     spriteFont = ScreenManager.Game.Content.Load<SpriteFont>("Kootenay");
     particleManager = new ParticleManager(ScreenManager.Game);
     if (!particleManager.HasTypeAlready(typeof(ExplosionParticleSystem)))
         particleManager.Register(new ExplosionParticleSystem(ScreenManager.Game, 1));
     particleManager.AddParticleSystem(typeof(ExplosionParticleSystem), new Vector2(235, 55));
     base.LoadContent();
 }
Beispiel #21
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            arial = Content.Load<SpriteFont>(AssetPrefix + "Arial13");

            colorTexture = Texture.New2D(GraphicsDevice, 1, 1, PixelFormat.R8G8B8A8_UNorm, new[] { Color.White });

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
Beispiel #22
0
    public GameWorld(int width, int height, ContentManager Content)
    {
        screenWidth = width;
        screenHeight = height;
        random = new Random();
        gameState = GameState.Playing;

        block = Content.Load<Texture2D>("block");
        font = Content.Load<SpriteFont>("SpelFont");
        grid = new TetrisGrid(block);
    }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            msMincho10 = Content.Load<SpriteFont>(AssetPrefix + "MSMincho10");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            for (int i = 0; i < VaryingStringLength; i++)
                varyingString.Append(' ');
        }
Beispiel #24
0
    /// <summary>
    /// Initialises the asset manager.
    /// </summary>
    /// <param name="coMan"></param>
    public static void Initialise(ContentManager coMan)
    {
        if (coMan != null)
        {
            coManager = coMan;

            DefTexture = coMan.Load<Texture2D>("Default/DefTexture");
            DefFont = coMan.Load<SpriteFont>("Default/DefFont");
        }
        else
            Console.WriteLine("The content manager send to the Asset class was null (empty)!");
    }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            testFont = Asset.Load<SpriteFont>("StaticFonts/TestBitmapFont");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);
            colorTexture = Texture.New2D(GraphicsDevice, 1, 1, PixelFormat.R8G8B8A8_UNorm, new[] { Color.White });

            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
Beispiel #26
0
        /// <summary>
        /// Load resource and construct ui components
        /// </summary>
        public override void Start()
        {
            // Load resources shared by different UI screens
            spriteFont = Asset.Load<SpriteFont>("Font");
            uiImages = Asset.Load<SpriteSheet>("UIImages");
            buttonImage = uiImages["button"];

            // Load and create specific UI screens.
            CreateMainMenuUI();
            CreateGameUI();
            CreateGameOverUI();
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var virtualResolution = new Vector3(GraphicsDevice.BackBuffer.ViewWidth, GraphicsDevice.BackBuffer.ViewHeight, 200);
            spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution };
            spheres = Asset.Load<SpriteSheet>("SpriteSphere");
            round = Asset.Load<Texture>("round");
            staticFont = Asset.Load<SpriteFont>("StaticFonts/CourierNew10");
            dynamicFont = Asset.Load<SpriteFont>("DynamicFonts/CourierNew10");
            colorTexture = Texture.New2D(GraphicsDevice, 1, 1, PixelFormat.R8G8B8A8_UNorm, new[] { Color.White });
        }
    public GameWorld(Point screenresolution, ContentManager c)
    {
        Asset.Initialise(c);

        screenResolution = screenresolution;

        topPaddle = new Paddle(new Vector2(20, screenResolution.Y / 2), Microsoft.Xna.Framework.Input.Keys.W, Microsoft.Xna.Framework.Input.Keys.S);
        bottomPaddle = new Paddle(new Vector2(screenResolution.X - 20, screenResolution.Y / 2), Microsoft.Xna.Framework.Input.Keys.Up, Microsoft.Xna.Framework.Input.Keys.Down);
        square = new Ball();

        background = Asset.LoadTexture2D("Background");
        this.font = Asset.LoadFont("Font");
    }
Beispiel #29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="player">The player seen on the screen</param>
 public World(ContentManager content, String startMap, int offsetX, int offsetY)
 {
     this.offsetX = offsetX;
     this.offsetY = offsetY;
     this.content = content;
     SpiritForce.TheWorld.Controller.init();
     eventsTriggered = new List<String>();
     loadMap(startMap);
     allowControl = true;
     narrativeTime = false;
     currentNarrative = null;
     font = content.Load<SpriteFont>("Font1");
 }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            spriteBatch = new SpriteBatch(GraphicsDevice);

            offlineTarget = Texture.New2D(GraphicsDevice, OfflineWidth, OfflineHeight, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);
            depthBuffer = Texture.New2D(GraphicsDevice, OfflineWidth, OfflineHeight, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this);

            uv = Asset.Load<Texture>("uv");
            spheres = Asset.Load<SpriteSheet>("SpriteSphere");

            arial = Asset.Load<SpriteFont>("StaticFonts/Arial13");

            width = GraphicsDevice.BackBuffer.ViewWidth;
            height = GraphicsDevice.BackBuffer.ViewHeight;
        }
Beispiel #31
0
 public void Initialize(ContentManager content)
 {
     _font = content.Load <SpriteFont>("MainFont");
 }
Beispiel #32
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            font        = Asset.Load <SpriteFont>("Font");

            wireframeState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back)
            {
                FillMode = FillMode.Wireframe
            });

            materials.Add(Asset.Load <Material>("NoTessellation"));
            materials.Add(Asset.Load <Material>("FlatTessellation"));
            materials.Add(Asset.Load <Material>("PNTessellation"));
            materials.Add(Asset.Load <Material>("PNTessellationAE"));
            materials.Add(Asset.Load <Material>("FlatTessellationDispl"));
            materials.Add(Asset.Load <Material>("FlatTessellationDisplAE"));
            materials.Add(Asset.Load <Material>("PNTessellationDisplAE"));

            var cube = new Entity("Cube")
            {
                new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel {
                    Size = new Vector3(80), MaterialInstance = { Material = materials[0] }
                }).GenerateModel(Services))
            };
            var sphere = new Entity("Sphere")
            {
                new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel {
                    Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] }
                }).GenerateModel(Services))
            };

            var megalodon = new Entity {
                new ModelComponent {
                    Model = Asset.Load <Model>("megalodon Model")
                }
            };

            megalodon.Transform.Position = new Vector3(0, -30f, -10f);

            var knight = new Entity {
                new ModelComponent {
                    Model = Asset.Load <Model>("knight Model")
                }
            };

            knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0);
            knight.Transform.Position         = new Vector3(0, -50f, 20f);
            knight.Transform.Scale            = new Vector3(0.6f);

            entities.Add(sphere);
            entities.Add(cube);
            entities.Add(megalodon);
            entities.Add(knight);

            camera          = new TestCamera();
            CameraComponent = camera.Camera;
            Script.Add(camera);

            LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true);
            GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White);

            ChangeModel(0);
            SetWireframe(true);

            camera.Position = new Vector3(25, 45, 80);
            camera.SetTarget(currentEntity, true);
        }
Beispiel #33
0
 /*********
 ** Public methods
 *********/
 /****
 ** Fonts
 ****/
 /// <summary>Get the dimensions of a space character.</summary>
 /// <param name="font">The font to measure.</param>
 public static float GetSpaceWidth(SpriteFont font)
 {
     return(font.MeasureString("A B").X - font.MeasureString("AB").X);
 }
Beispiel #34
0
 public override void OnMouseClick(EventArgs e)
 {
     currrentFont = _clickedFont;
     currentImage = _actionPerformedImage;
     base.OnMouseClick(e);
 }
 public ShadowText(string text, SpriteFont font, Color color)
 {
     this.text  = text;
     this.font  = font;
     this.color = color;
 }
        public void Draw(Vector2 position, int width)
        {
#if TRACE
            // Reset update count.
            Interlocked.Exchange(ref updateCount, 0);

            // Gets SpriteBatch, SpriteFont, and WhiteTexture from DebugManager.
            SpriteBatch spriteBatch = debugManager.SpriteBatch;
            SpriteFont  font        = debugManager.DebugFont;
            Texture2D   texture     = debugManager.WhiteTexture;

            // Adjust size and position based of number of bars we should draw.
            int   height  = 0;
            float maxTime = 0;
            foreach (MarkerCollection bar in prevLog.Bars)
            {
                if (bar.MarkCount > 0)
                {
                    height += BarHeight + BarPadding * 2;
                    maxTime = Math.Max(maxTime,
                                       bar.Markers[bar.MarkCount - 1].EndTime);
                }
            }

            // Auto display frame adjustment.
            // For example, if the entire process of frame doesn't finish in less than 16.6ms
            // thin it will adjust display frame duration as 33.3ms.
            const float frameSpan  = 1.0f / 60.0f * 1000f;
            float       sampleSpan = (float)sampleFrames * frameSpan;

            if (maxTime > sampleSpan)
            {
                frameAdjust = Math.Max(0, frameAdjust) + 1;
            }
            else
            {
                frameAdjust = Math.Min(0, frameAdjust) - 1;
            }

            if (Math.Abs(frameAdjust) > AutoAdjustDelay)
            {
                sampleFrames = Math.Min(MaxSampleFrames, sampleFrames);
                sampleFrames =
                    Math.Max(TargetSampleFrames, (int)(maxTime / frameSpan) + 1);

                frameAdjust = 0;
            }

            // Compute factor that converts from ms to pixel.
            float msToPs = (float)width / sampleSpan;

            // Draw start position.
            int startY = (int)position.Y - (height - BarHeight);

            // Current y position.
            int y = startY;

            spriteBatch.Begin();

            // Draw transparency background.
            Rectangle rc = new Rectangle((int)position.X, y, width, height);
            spriteBatch.Draw(texture, rc, new Color(0, 0, 0, 128));

            // Draw markers for each bars.
            rc.Height = BarHeight;
            foreach (MarkerCollection bar in prevLog.Bars)
            {
                rc.Y = y + BarPadding;
                if (bar.MarkCount > 0)
                {
                    for (int j = 0; j < bar.MarkCount; ++j)
                    {
                        float bt = bar.Markers[j].BeginTime;
                        float et = bar.Markers[j].EndTime;
                        int   sx = (int)(position.X + bt * msToPs);
                        int   ex = (int)(position.X + et * msToPs);
                        rc.X     = sx;
                        rc.Width = Math.Max(ex - sx, 1);

                        spriteBatch.Draw(texture, rc, bar.Markers[j].Color);
                    }
                }

                y += BarHeight + BarPadding;
            }

            // Draw grid lines.
            // Each grid represents ms.
            rc = new Rectangle((int)position.X, (int)startY, 1, height);
            for (float t = 1.0f; t < sampleSpan; t += 1.0f)
            {
                rc.X = (int)(position.X + t * msToPs);
                spriteBatch.Draw(texture, rc, Color.Gray);
            }

            // Draw frame grid.
            for (int i = 0; i <= sampleFrames; ++i)
            {
                rc.X = (int)(position.X + frameSpan * (float)i * msToPs);
                spriteBatch.Draw(texture, rc, Color.White);
            }

            // Draw log.
            if (ShowLog)
            {
                // Generate log string.
                y = startY - font.LineSpacing;
                logString.Length = 0;
                foreach (MarkerInfo markerInfo in markers)
                {
                    for (int i = 0; i < MaxBars; ++i)
                    {
                        if (markerInfo.Logs[i].Initialized)
                        {
                            if (logString.Length > 0)
                            {
                                logString.Append("\n");
                            }

                            logString.Append(" Bar ");
                            logString.AppendNumber(i);
                            logString.Append(" ");
                            logString.Append(markerInfo.Name);

                            logString.Append(" Avg.:");
                            logString.AppendNumber(markerInfo.Logs[i].SnapAvg);
                            logString.Append("ms ");

                            y -= font.LineSpacing;
                        }
                    }
                }

                // Compute background size and draw it.
                Vector2 size = font.MeasureString(logString);
                rc = new Rectangle((int)position.X, (int)y, (int)size.X + 12, (int)size.Y);
                spriteBatch.Draw(texture, rc, new Color(0, 0, 0, 128));

                // Draw log string.
                spriteBatch.DrawString(font, logString,
                                       new Vector2(position.X + 12, y), Color.White);


                // Draw log color boxes.
                y += (int)((float)font.LineSpacing * 0.3f);
                rc = new Rectangle((int)position.X + 4, y, 10, 10);
                Rectangle rc2 = new Rectangle((int)position.X + 5, y + 1, 8, 8);
                foreach (MarkerInfo markerInfo in markers)
                {
                    for (int i = 0; i < MaxBars; ++i)
                    {
                        if (markerInfo.Logs[i].Initialized)
                        {
                            rc.Y  = y;
                            rc2.Y = y + 1;
                            spriteBatch.Draw(texture, rc, Color.White);
                            spriteBatch.Draw(texture, rc2, markerInfo.Logs[i].Color);

                            y += font.LineSpacing;
                        }
                    }
                }
            }

            spriteBatch.End();
#endif
        }
Beispiel #37
0
 protected override void LoadContent()
 {
     base.LoadContent();
     font = Content.Load <SpriteFont>("courier");
 }
Beispiel #38
0
 public override void OnMouseEnter(EventArgs e)
 {
     currrentFont = _focusedFont;
     currentImage = _focusedImage;
     base.OnMouseEnter(e);
 }
Beispiel #39
0
        public void LoadContent()
        {
            content = new ContentManager(ScreenManager.Instance.content.ServiceProvider, "Content");

            if (path != String.Empty)
            {
                texture = content.Load <Texture2D>(path);
            }

            font = content.Load <SpriteFont>(fontName);

            Vector2 dimensions = Vector2.Zero;

            if (texture != null)
            {
                dimensions.X += texture.Width;
            }
            dimensions.X += font.MeasureString(text).X;

            if (texture != null)
            {
                dimensions.Y = Math.Max(texture.Height, font.MeasureString(text).Y);
            }
            else
            {
                dimensions.Y = font.MeasureString(text).Y;
            }

            if (srcRect == Rectangle.Empty)
            {
                srcRect = new Rectangle(0, 0, (int)dimensions.X, (int)dimensions.Y);
            }

            renderTarget = new RenderTarget2D(ScreenManager.Instance.graphicsDevice, (int)dimensions.X, (int)dimensions.Y);
            ScreenManager.Instance.graphicsDevice.SetRenderTarget(renderTarget);
            ScreenManager.Instance.graphicsDevice.Clear(Color.Transparent);
            ScreenManager.Instance.spriteBatch.Begin();

            if (texture != null)
            {
                ScreenManager.Instance.spriteBatch.Draw(texture, Vector2.Zero, Color.White);
            }
            ScreenManager.Instance.spriteBatch.DrawString(font, text, Vector2.Zero, Color.White);

            ScreenManager.Instance.spriteBatch.End();

            texture = renderTarget;

            ScreenManager.Instance.graphicsDevice.SetRenderTarget(null);

            SetEffect <FadeEffect>(ref fadeEffect);

            if (effects != String.Empty)
            {
                string[] split = effects.Split(':');
                foreach (string item in split)
                {
                    ActivateEffect(item);
                }
            }
        }
Beispiel #40
0
        /// <summary>
        /// Create a new button.
        /// </summary>
        /// <param name="position">Screen coordinates of the button.</param>
        /// <param name="dimensions">Screen dimensions of the button.</param>
        /// <param name="texture">Texture to display on the button.</param>
        /// <param name="text">Text to display on the button.</param>
        /// <param name="font">Font to use for the button text.</param>
        /// <param name="defaultColor">The default colour to render text as on this button.</param>
        /// <param name="hoverColor">The colour to render text as when the user moves the mouse over this button.</param>
        /// <param name="command">The command triggered by this button when clicked.</param>
        public Button(Vector2 position, Vector2 dimensions, Texture2D texture, string text, SpriteFont font, Color defaultColor, Color hoverColor, MenuCommand command)
            : base(position, dimensions, texture, text, font)
        {
            // Set parameters
            this.defaultColor = defaultColor;
            this.hoverColor   = hoverColor;
            this.currentColor = defaultColor;
            this.command      = command;

            pressed = false;
        }
Beispiel #41
0
 public static void DrawString(this SpriteBatch batch, SpriteFont font, string text, Vector2 pos, Color col, float a, float s)
 {
     batch.DrawString(font, text, pos, col, a, Vector2.Zero, s, SpriteEffects.None, 0f);
 }
Beispiel #42
0
        public void LoadContent()
        {
            // Get the content
            _content = ScreenManager.Instance.Content;

            // Load the texture
            if (Path != string.Empty)
            {
                Texture = _content.Load <Texture2D>(Path);
            }

            // Load the font
            _font = _content.Load <SpriteFont>(FontName);

            // Get the dimensions
            Vector2 dimensions = Vector2.Zero;

            if (Texture != null)
            {
                dimensions.X += Texture.Width;
            }
            dimensions.X += _font.MeasureString(Text).X;
            if (Texture != null)
            {
                dimensions.Y = Math.Max(Texture.Height, _font.MeasureString(Text).Y);
            }
            else
            {
                dimensions.Y = _font.MeasureString(Text).Y;
            }

            // Get the source rect of the image
            if (SourceRect == Rectangle.Empty)
            {
                SourceRect = new Rectangle(0, 0, (int)dimensions.X, (int)dimensions.Y);
            }

            // Do graphics magic to draw things
            _renderTarget = new RenderTarget2D(ScreenManager.Instance.GraphicsDevice, (int)dimensions.X, (int)dimensions.Y);
            ScreenManager.Instance.GraphicsDevice.SetRenderTarget(_renderTarget);
            ScreenManager.Instance.GraphicsDevice.Clear(Color.Transparent);
            ScreenManager.Instance.SpriteBatch.Begin();
            if (Texture != null)
            {
                ScreenManager.Instance.SpriteBatch.Draw(Texture, Vector2.Zero, Color.White);
            }
            ScreenManager.Instance.SpriteBatch.DrawString(_font, Text, Vector2.Zero, Color.White);
            ScreenManager.Instance.SpriteBatch.End();

            // Store the render target and then reset it
            Texture = _renderTarget;
            ScreenManager.Instance.GraphicsDevice.SetRenderTarget(null);

            // Handle effects
            SetEffect <FadeEffect>(ref FadeEffect);
            SetEffect <SpriteSheetEffect>(ref SpriteSheetEffect);

            // Activate image effects
            if (Effects != String.Empty)
            {
                string[] split = Effects.Split(':');
                foreach (string item in split)
                {
                    ActivateEffect(item);
                }
            }
        }
Beispiel #43
0
        private static void InvalidateFont(object propertyOwner, PropertyKey <SpriteFont> propertyKey, SpriteFont propertyOldValue)
        {
            var element = (UIElement)propertyOwner;

            element.InvalidateMeasure();
        }
Beispiel #44
0
 internal LevelSelectionButton(string name, SpriteFont font, GraphicsDevice device) :
     base(name, font, device)
 {
 }
Beispiel #45
0
 public Soldier(int ID, Texture2D bTexture, Texture2D sTexture, Texture2D tbTexture, SpriteFont font, Color color, Vector2 location, float layer)
     : base(ID, bTexture, sTexture, tbTexture, font, color, location, layer)
 {
     rotateState = RotateState.Standing;
     rotations   = new Stack <bool?>();
 }
Beispiel #46
0
        public static Label CreateLabel(string text)
        {
            SpriteFont labelFont = FontLoader.Load("MenuFont");

            return(new Label(labelFont, text));
        }
 public InstructionScreen(Game game, SpriteBatch spriteBatch, SpriteFont spriteFont, SpriteFont menuFont) : base(game, spriteBatch)
 {
     string[] menuItems = { "Got it!" };
     menuComponent = new MenuComponent(game, spriteBatch, menuFont, menuItems);
     Components.Add(menuComponent);
     this.spriteFont = spriteFont;
 }
Beispiel #48
0
 public override void OnMouseLeave(EventArgs e)
 {
     currrentFont = _font;
     currentImage = _backgroundImage;
     base.OnMouseLeave(e);
 }
Beispiel #49
0
        /// <summary>Draw a block of text to the screen with the specified wrap width.</summary>
        /// <param name="batch">The sprite batch.</param>
        /// <param name="font">The sprite font.</param>
        /// <param name="text">The block of text to write.</param>
        /// <param name="position">The position at which to draw the text.</param>
        /// <param name="wrapWidth">The width at which to wrap the text.</param>
        /// <param name="color">The text color.</param>
        /// <param name="bold">Whether to draw bold text.</param>
        /// <param name="scale">The font scale.</param>
        /// <returns>Returns the text dimensions.</returns>
        public static Vector2 DrawTextBlock(this SpriteBatch batch, SpriteFont font, string text, Vector2 position, float wrapWidth, Color?color = null, bool bold = false, float scale = 1)
        {
            if (text == null)
            {
                return(new Vector2(0, 0));
            }

            // get word list
            List <string> words = new List <string>();

            foreach (string word in text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                // split on newlines
                string wordPart = word;
                int    newlineIndex;
                while ((newlineIndex = wordPart.IndexOf(Environment.NewLine, StringComparison.InvariantCulture)) >= 0)
                {
                    if (newlineIndex == 0)
                    {
                        words.Add(Environment.NewLine);
                        wordPart = wordPart.Substring(Environment.NewLine.Length);
                    }
                    else if (newlineIndex > 0)
                    {
                        words.Add(wordPart.Substring(0, newlineIndex));
                        words.Add(Environment.NewLine);
                        wordPart = wordPart.Substring(newlineIndex + Environment.NewLine.Length);
                    }
                }

                // add remaining word (after newline split)
                if (wordPart.Length > 0)
                {
                    words.Add(wordPart);
                }
            }

            // track draw values
            float xOffset     = 0;
            float yOffset     = 0;
            float lineHeight  = font.MeasureString("ABC").Y *scale;
            float spaceWidth  = CommonHelper.GetSpaceWidth(font) * scale;
            float blockWidth  = 0;
            float blockHeight = lineHeight;

            foreach (string word in words)
            {
                // check wrap width
                float wordWidth = font.MeasureString(word).X *scale;
                if (word == Environment.NewLine || ((wordWidth + xOffset) > wrapWidth && (int)xOffset != 0))
                {
                    xOffset      = 0;
                    yOffset     += lineHeight;
                    blockHeight += lineHeight;
                }
                if (word == Environment.NewLine)
                {
                    continue;
                }

                // draw text
                Vector2 wordPosition = new Vector2(position.X + xOffset, position.Y + yOffset);
                if (bold)
                {
                    Utility.drawBoldText(batch, word, font, wordPosition, color ?? Color.Black, scale);
                }
                else
                {
                    batch.DrawString(font, word, wordPosition, color ?? Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 1);
                }

                // update draw values
                if (xOffset + wordWidth > blockWidth)
                {
                    blockWidth = xOffset + wordWidth;
                }
                xOffset += wordWidth + spaceWidth;
            }

            // return text position & dimensions
            return(new Vector2(blockWidth, blockHeight));
        }
Beispiel #50
0
        void tileDisplay1_OnInitialize(object sender, EventArgs e)
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            string buildError;
            string currentDirectory = FileHelper.GetAssemblyDirectory();

            ContentBuilder builder = new ContentBuilder();

            // create content manager
            ContentManager manager = new ContentManager(tileDisplay1.Services,
                                                        builder.OutputDirectory);

            contentManager = new WinformsContentManager(builder, manager);


            spriteFont = contentManager.LoadContent <SpriteFont>
                             (currentDirectory + "\\Content\\hudFont.spritefont", null,
                             "FontDescriptionProcessor", out buildError, false, false);

            FontLarge = contentManager.LoadContent <SpriteFont>
                            (currentDirectory + "\\Content\\font_large.spritefont", null,
                            "FontDescriptionProcessor", out buildError, false, false);

            FontSmall = contentManager.LoadContent <SpriteFont>
                            (currentDirectory + "\\Content\\font_small.spritefont", null,
                            "FontDescriptionProcessor", out buildError, false, false);

            FillTexture = new Texture2D(GraphicsDevice, 1, 1);
            FillTexture.SetData <Color>(new Color[] { Color.White });

            using (Stream stream = File.OpenRead("Content/tile.png"))
            {
                tileTexture = Texture2D.FromStream(GraphicsDevice, stream);
            }

            using (Stream stream1 = File.OpenRead("Content/unPassable.png"))
            {
                unPassable = Texture2D.FromStream(GraphicsDevice, stream1);
            }

            using (Stream stream2 = File.OpenRead("Content/Platform.png"))
            {
                platformTile = Texture2D.FromStream(GraphicsDevice, stream2);
            }

            using (Stream stream3 = File.OpenRead("Content/PlayerPoint.png"))
            {
                PlayerPoint = Texture2D.FromStream(GraphicsDevice, stream3);
            }

            using (Stream stream4 = File.OpenRead("Content/EnemyPoint.png"))
            {
                EnemyPoint = Texture2D.FromStream(GraphicsDevice, stream4);
            }

            using (Stream stream5 = File.OpenRead("Content/Normal.png"))
            {
                normalTile = Texture2D.FromStream(GraphicsDevice, stream5);
            }

            using (Stream stream6 = File.OpenRead("Content/MiscPoint.png"))
            {
                MiscPoint = Texture2D.FromStream(GraphicsDevice, stream6);
            }

            collisionPics.Add("Unpassable", unPassable);
            collisionPics.Add("NormalTile", normalTile);
            collisionPics.Add("Platform", platformTile);
            collisionPics.Add("Ladder", platformTile);
            collisionPics.Add("Patrol", platformTile);



            collisionTiles.Items.Add("Erase");

            foreach (var picName in collisionPics)
            {
                collisionTiles.Items.Add(picName.Key);
            }

            collisionTiles.Items.Add("SpawnDraw");

            point.ReadFile(point.PlayerFile);
            point.ReadFile(point.EnemyFile);
            point.ReadFile(point.MiscFile);

            AssociateBox.Items.Add("Do Nothing");
            AssociateBox.Items.Add("Associate");
            AssociateBox.Items.Add("Unassociate");

            AssociateBox.SelectedIndex = 0;
        }