Hello Guest

Author Topic: Text Creation  (Read 1166 times)

0 Members and 1 Guest are viewing this topic.

Semeon

  • Member
  • Posts: 2
    • View Profile
Text Creation
« on: July 02, 2016, 07:56:26 AM »
Hello,
I was wondering how I could create text within the framework. Now I know there is a documentations page but sadly I wasn't able to figure out what I had to do to create some basic text (ex. Hello World).
Please help me out!

TaintedGoat

  • Member
  • Posts: 8
    • View Profile
Re: Text Creation
« Reply #1 on: July 02, 2016, 08:19:45 AM »
Hey Semeon! This forum isnt really visited by the frequent otter users. I would advice you to join the Slack Team if you're interested in this project, there you can ask questions and talk with the frequent Otter users. Here's the link to join http://otter2d.com/slack.php

To display text you can create a 'Text' graphic and add it to an 'Entity', that entity has to later be added to a 'Scene'.
Or you can override the 'Render' method on a 'Scene' and write inside Draw.Text(string,fontSize) this method however has the limitation of not being able to change color.


The first method can be achieved by doing this. For example
Code: [Select]
using Otter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartGame {
  class Program {
    static void Main(string[] args) {
      // Create a game
      var game = new Game("Displaying text: Entities", 640, 480, 60, false);
      Scene scene = new Scene();//Create the scene that will contain the entity 
      Entity textEntity = new Entity(100,100);//Create the entity that will have the Text graphic
      Text text = new Text("Content", 24);//Create the text graphic.
     
      text.String = "Other content";//Change the text displayed
      text.Color = Color.Random;//Change the color

      textEntity.AddGraphic(text);//Add the graphic to the entity
      scene.Add(textEntity);//Add the entity to the scene
      game.Start(scene);// Start from the scene you just created
    }
  }
}

If you want to use the second method would look something like this

Code: [Select]
using Otter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartGame {
  class Program {
    static void Main(string[] args) {
      // Create a game
      var game = new Game("Displaying text: Draw call", 640, 480, 60, false);
      DisplayScene scene = new DisplayScene();
      game.Start(scene);// Start from the scene you just created
    }
  }
  class DisplayScene : Scene{
      public override void Render(){
          base.Render();
          Draw.Text("Content",24,100,100);
      }
  }
}

I hope it was helpful.

Semeon

  • Member
  • Posts: 2
    • View Profile
Re: Text Creation
« Reply #2 on: July 02, 2016, 11:48:16 AM »
Hey,
Thank you for your time I figured it out thanks for the support/help have a good day!