Advertisement
Guest User

SpriteFont

a guest
Aug 18th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public var letter : String;
  2. public var font : Sprite[];
  3.  
  4.  
  5.  
  6.  function Awake(){
  7.    
  8.     font = Resources.LoadAll("Font/SpriteFont", Sprite) as Sprite[];
  9.    
  10.     if (font != null){
  11.    
  12.         var Text = new SpriteText();
  13.         Text.Letters = letter;
  14.         Text.write("A",0,0);
  15.        
  16.     }else { Debug.LogWarning("Loaded no SpriteSheet for Font.");}
  17.    
  18.  }
  19.  
  20.  
  21. public class SpriteText{
  22.    
  23.  public var font : Sprite[];
  24.  public var box : Sprite[];
  25.  public var letter : char;
  26.    
  27.     public var letters : String;
  28.         public function get Letters() : String
  29.         {       return letters; }
  30.    
  31.         public function set Letters(value : String)
  32.         {       letters = value;}
  33.    
  34.    
  35.     public function write(text : String,x : float,y : float){
  36.         Debug.Log("write");
  37.         var line : int;
  38.    
  39.         for (var i = 0; i < text.Length; i++){
  40.                 Debug.Log("Get " + text[i]);       
  41.                 letter = text[i];
  42.                    
  43.                 for ( var j = 0; j < letters.Length+1; j++){
  44.                    
  45.                     if (j == letters.Length+1){
  46.                      Debug.LogError("Letter not in the available Set");
  47.                     }
  48.                    
  49.                     if (letter == letters[j]){
  50.                         var frame;
  51.                         Debug.Log("Should Instantiate Letter " + letter);
  52.                        
  53.                         //font = Resources.LoadAll("Font") as Sprite[];
  54.                         //Sprite.Create(font);
  55.                        
  56.                         var Char = new GameObject();
  57.                         Char.AddComponent(SpriteRenderer);
  58.                         Char.GetComponent(SpriteRenderer).sprite = font[0];
  59.                         Char.transform.position.Set(x + i*6f,y + line * 7f, 0.0);
  60.                        
  61.                         j = letters.Length+1;
  62.                     }
  63.                                            
  64.                 }
  65.                    
  66.          }           
  67.     }      
  68.    
  69.     public function delete(){
  70.    
  71.     }
  72.    
  73.  
  74.  
  75. }
  76.  
  77. public class TextBox {
  78.  
  79.     function TextBox(content : String) {
  80.        
  81.         if (content == null){
  82.             content = "no content!";
  83.         }
  84.         var Text = new SpriteText();
  85.         Text.write(content,0,0);
  86.                
  87.     }
  88.  
  89. }
  90.  
  91. public class TextBubble {
  92.        
  93.         function TextBubble(){
  94.        
  95.         }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement