public TextRenderer() { actor = new("TextActor"); textRenderComponent = new(actor); font = Font.Load("/Game/Tests/PlayFont"); material = Material.Load("/Game/Tests/PlayFontMaterial"); }
protected override void Initialize() { this._playTextRenderer = this.FindComponentInChildren("PlayText") as TextRenderComponent; this._exitTextRenderer = this.FindComponentInChildren("ExitText") as TextRenderComponent; this._selectionRenderer = this.GetChild <SpriteAnimationComponent>(); this._gameStateComponent = this.Scene.GetAllComponentsOfType <GameStateComponent>().First(); this._inputManager = this.Scene.GetModule <InputManager>(); }
/// <summary> /// Render a string to the screen /// </summary> /// <param name="spriteBatch"></param> /// <param name="gameTime"></param> public void Render(SpriteBatch spriteBatch, GameTime gameTime) { List <Entity> entities = SceneManager.Instance.GetActiveScene().GetAllEntities(); foreach (Entity e in entities) { if (e.Visible) { TextRenderComponent t = ComponentManager.Instance.GetEntityComponent <TextRenderComponent>(e); Position2DComponent p = ComponentManager.Instance.GetEntityComponent <Position2DComponent>(e); if (p != null && t != null) { spriteBatch.DrawString(t.Font, t.Text, p.Position, t.TextColor); } } } }
public override void Update(GameTime gameTime) { // Check if there events to process. if (scoreEvents.Count == 0) { return; } // Get HUD world. IWorld world = worldManager.GetWorld((int)WorldID.HudWorld); // Get text render component registry. IComponentRegistry <TextRenderComponent> textRenders = (IComponentRegistry <TextRenderComponent>)world.ComponentManager.GetRegistry <TextRenderComponent>(); foreach (ScoreEvent score in scoreEvents) { // Update score and text. if (score.Player == 1) { player1Score += score.Amount; TextRenderComponent component = textRenders.Get(player1Text); component.Text = player1Score.ToString(); textRenders.Set(component); } else { player2Score += score.Amount; TextRenderComponent component = textRenders.Get(player2Text); component.Text = player2Score.ToString(); textRenders.Set(component); } } // Clear list. scoreEvents.Clear(); }
protected override void Initialize() { this._textRenderer = this.GetChild <PixelTextRendererComponent>(); }
public override void Run() { // If there is no state, setup world. if (State == WorldState.None) { // Create a renderable text entity for "Pong". int pongTextID = EntityManager.CreateEntity(); // Load font. SpriteFont pongFont = ContentManager.Load <SpriteFont>("Exo-2-SemiBold"); // Create components. PositionComponent pongTextPosition = new PositionComponent(pongTextID, engine.ScreenWidth / 2 - 40, 50); TextRenderComponent pongTextSpriteFont = new TextRenderComponent(pongTextID, Color.Black, pongFont, "PONG"); // Add components. ComponentManager .SetComponent(pongTextPosition) .SetComponent(pongTextSpriteFont); // Create renderable text entity for player 1 score. int player1ID = EntityManager.CreateEntity(); // Load font. SpriteFont player1Font = ContentManager.Load <SpriteFont>("Exo-2-SemiBold"); // Create components. PositionComponent player1Position = new PositionComponent(player1ID, 50, 50); TextRenderComponent player1SpriteFont = new TextRenderComponent(player1ID, Color.Black, player1Font, "0"); // Add components. ComponentManager .SetComponent(player1Position) .SetComponent(player1SpriteFont); // Emit event. EventManager.Emit(new ScoreTextCreateEvent(player1ID, 1)); // Create renderable text entity for player 2 score. int player2ID = EntityManager.CreateEntity(); // Load font. SpriteFont player2Font = ContentManager.Load <SpriteFont>("Exo-2-SemiBold"); // Create components. PositionComponent player2Position = new PositionComponent(player2ID, engine.ScreenWidth - 75, 50); TextRenderComponent player2SpriteFont = new TextRenderComponent(player2ID, Color.Black, player2Font, "0"); // Add components. ComponentManager .SetComponent(player2Position) .SetComponent(player2SpriteFont); // Emit event. EventManager.Emit(new ScoreTextCreateEvent(player2ID, 2)); } base.Run(); }