Getting orxTEXT (and orxFONT) via orxOBJECT

edited September 2016 in Help request
Just trying to get an orxFONT and orxTEXT via an orxOBJECT.

My initial attempt was:
[AlphabetObject]
Graphic		= AlphabetGraphic
Position	= (310, 740, -0.1)
Group = titles 
Color = (255, 0, 0)
Scale = 2

[AlphabetGraphic]
Pivot = top left
Text  = AlphabetText

[AlphabetText]
Font	=	LCDFont
String	=	ABCDEF


	alphabetObject = orxObject_CreateFromConfig("AlphabetObject");
	
	orxGRAPHIC *graphic = orxGRAPHIC(orxOBJECT_GET_STRUCTURE( alphabetObject, GRAPHIC) ) ;
	
	orxSTRUCTURE *st = orxSTRUCTURE( graphic );
	orxTEXT *t2 = orxSTRUCTURE_GET_POINTER(st, TEXT); //returns null

	orxTEXT *text = orxTEXT(linkedGraphic ); //also returns null

Comments

  • edited September 2016
    Everything's fine until:
        // Well this one is fine as well, but it doesn't bring us anything =)
        orxSTRUCTURE *st = orxSTRUCTURE( graphic );
    
        // Here you're trying to interpret the structure, which is a graphic, as a text -> orxNULL
        orxTEXT *t2 = orxSTRUCTURE_GET_POINTER(st, TEXT); //returns null 
     
        // Here you're trying the same thing (orxTEXT is a shortcut for the long version in the previous line), except that I don't know where linkedGraphic comes from :)
        orxTEXT *text = orxTEXT(linkedGraphic ); //also returns null
    

    When you have your graphic, you should use the orxGraphic API on it to extract its data (which can either be a texture or a text):
      orxSTRUCTURE *st = orxGraphic_GetData(graphic);
    

    Now you might want to get it as a text (if it's a texture, you'll get orxNULL instead):
      orxTEXT *text = orxTEXT(st);
    

    If you'd rather, you could always call orxStructure_GetID() to see what kind of structure it is beforehand, but the "cast" will do just as well.

    Now that you have a text, you need the orxText API to extract its font, if there's one:
      orxFONT *font = orxText_GetFont(text);
    
  • edited September 2016
    Ah thanks! I did miss that function in the Graphic API.
Sign In or Register to comment.