20,741
edits
m (→Adding Text Elements: adapt the example so that it works properly with the two canvas setup stubs at the beginning of the article) |
|||
| Line 71: | Line 71: | ||
! Screenshot !! Code !! | ! Screenshot !! Code !! | ||
|- | |- | ||
| | | [[File:CanvasText-Hello-World.png|thumb|Screen shot showing the CanvasText example contributed by Necolatis]]|| | ||
| | | | ||
{{Note|This assumes that you already have a top-level root group set up, and named it '''root'''.}} | {{Note|This assumes that you already have a top-level root group set up, and named it '''root'''.}} | ||
<syntaxhighlight lang="nasal" enclose="div"> | <syntaxhighlight lang="nasal" enclose="div"> | ||
var myText = root.createChild("text") | |||
.setText("Hello world!") | .setText("Hello world!") | ||
.setFontSize( | .setFontSize(20, 0.9) # font size (in texels) and font aspect ratio | ||
.setColor(1, | .setColor(1,0,0,1) # red, fully opaque | ||
.setAlignment("center-center") # how the text is aligned to where you place it | .setAlignment("center-center") # how the text is aligned to where you place it | ||
.setTranslation( | .setTranslation(160, 80); # where to place the text | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||