how to change fontsize during the game in XNA?

后端 未结 3 1801
心在旅途
心在旅途 2021-02-20 16:55

I need to use different fontsize of spritefont, Have to I create new spritefont for the each size?

3条回答
  •  温柔的废话
    2021-02-20 17:48

    Suppose the SpriteFont you are using is named x.spritefont. Do the following to create new SpriteFont for each size.

    • Open the x.spritefont file from solution explorer.
    • Go to the tag and edit it to your desired font size.
    • To make multiple size font, duplicate the file and change the tags accordingly. Rename the files with size appended at last for easy remembering.

    Now create multiple instances of SpriteFont and load them accordingly.

    SpriteFont sf_s10;
    SpriteFont sf_s14;
    
    protected override void LoadContent()
    {
      sf_s10 = Content.Load("x_10");
      sf_s14 = Content.Load("x_14");
      //OTHER LOADS 
    }
    

    to dynamically change fontSize, do the following:

    SpriteFont current_font;
    
    protected override void Update(GameTime gameTime)
    {
      if(/*SOME_CONDITION_TO_DECREASE_SIZE*/)
        current_font=sf_s10;
    
      if(/*SOME_CONDITION_TO_INCREASE_SIZE*/)
        current_font=sf_s14;
    }
    

提交回复
热议问题