Canvas snippets: Difference between revisions

Jump to navigation Jump to search
m
→‎Adding Text Elements: adapt the example so that it works properly with the two canvas setup stubs at the beginning of the article
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 !!  
|-
|-
| please upload ...||  
| [[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")
    var myText = root.createChild("text")
       .setText("Hello world!")
       .setText("Hello world!")
       .setFontSize(80, 0.9)          # font size (in texels) and font aspect ratio
       .setFontSize(20, 0.9)          # font size (in texels) and font aspect ratio
       .setColor(1,1,1,1)            # white, fully opaque
       .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(250, 250);    # where to place the text
       .setTranslation(160, 80);    # where to place the text
</syntaxhighlight>
</syntaxhighlight>
|-
|-

Navigation menu