Difference between revisions of "DrawIconByName"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
(3 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
</onlyinclude>
 
</onlyinclude>
  
As this is GUI-related this is client only - it should be wrapped in "if ( getNet().isClient( ))" or in a client-only script.
+
As this is GUI-related it is client only - it should be wrapped in "if ( getNet().isClient() )" or be in a client-only script.
 +
 
 +
This method is part of the GUI namespace so you need to prefix calls to it with 'GUI::'.
  
 
This method has two variants. They both specify the token name as a string and the position to draw the icon at with a [[position2d]]i but one also specifies a scale factor for the icon as a float.
 
This method has two variants. They both specify the token name as a string and the position to draw the icon at with a [[position2d]]i but one also specifies a scale factor for the icon as a float.
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
void DrawIconByName( const string &iconName, position2di pos )
+
void GUI::DrawIconByName( const string &iconName, position2di pos )
void DrawIconByName( const string &iconName, position2di pos, f32 scale )
+
void GUI::DrawIconByName( const string &iconName, position2di pos, f32 scale )
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Scripting]]
 
[[Category:Scripting]]
 
[[Category:Global Functions]]
 
[[Category:Global Functions]]
 +
 +
'''Example'''
 +
 +
<syntaxhighlight lang="cpp">
 +
void onRender(CRules@ this)
 +
{
 +
AddIconToken("$corpse$", "GUI/BodyIcon.png", dimension2di(32, 32), 0, SColor(255, 125, 25, 5));
 +
GUI::DrawIconByName("$corpse$", position2di(getScreenWidth()/2 - 50, getScreenHeight()/2 - 50), 2);
 +
 +
}
 +
</syntaxhighlight>
 +
 +
[[File:GUIIcon.png]]

Latest revision as of 23:23, 28 September 2012

Draws an icon added by AddIconToken using its token name.


As this is GUI-related it is client only - it should be wrapped in "if ( getNet().isClient() )" or be in a client-only script.

This method is part of the GUI namespace so you need to prefix calls to it with 'GUI::'.

This method has two variants. They both specify the token name as a string and the position to draw the icon at with a position2di but one also specifies a scale factor for the icon as a float.

void GUI::DrawIconByName( const string &iconName, position2di pos )
void GUI::DrawIconByName( const string &iconName, position2di pos, f32 scale )

Example

void onRender(CRules@ this)
{	
	AddIconToken("$corpse$", "GUI/BodyIcon.png", dimension2di(32, 32), 0, SColor(255, 125, 25, 5));
	GUI::DrawIconByName("$corpse$", position2di(getScreenWidth()/2 - 50, getScreenHeight()/2 - 50), 2);
 
}

GUIIcon.png