Skip to content

Instantly share code, notes, and snippets.

@coronarob coronarob/1.lua
Created Feb 1, 2015

Embed
What would you like to do?
Code from Tutorial: Methods for Positioning Text (http://coronalabs.com/blog/2014/02/11/tutorial-methods-for-positioning-text/)
local myText = display.newText( "Hello World", 200, 200, native.systemFont, 16 )
local myText = display.newText( "Hello World", 0, 0, native.systemFont, 16 )
myText:setFillColor( 0, 0, 0 )
myText.anchorX = 0
myText.x = 10
myText.y = 100
local options = {
text = "Hello World",
x = display.contentCenterX,
y = display.contentCenterY,
fontSize = 24,
width = 200,
height = 0,
align = "left"
}
local textBox = display.newText( options )
textBox:setFillColor( 0, 0, 0 )
local myText = [[This is a long, multi-line string where we are randomly
inserting some blank
lines
of text.]]
local options = {
text = myText,
x = display.contentCenterX,
y = display.contentCenterY,
width = 200,
height = 300,
fontSize = 24,
align = "left"
}
local textField = display.newText( options )
textField:setFillColor( 0, 0, 0 )
local myText = [[This is a long, multi-line string where we are randomly
inserting some blank
lines
of text.]]
local options = {
text = myText,
x = display.contentCenterX,
y = display.contentCenterY,
width = 200,
height = 300,
fontSize = 24,
align = "center"
}
--Output the text box with the specified options
local textField = display.newText( options )
textField:setFillColor( 0, 0, 0 )
local myText = [[This is a long, multi-line string where we are randomly
inserting some blank
lines
of text.]]
local options = {
text = myText,
x = display.contentCenterX,
y = display.contentCenterY,
width = 200,
height = 300,
fontSize = 24,
align = "right"
}
--Output the text box with the specified options
local textField = display.newText( options )
textField:setFillColor( 0, 0, 0 )
longString = [[This is a really
long string
with multiple
line breaks.]]
--OR...
longString = "This is a really\nlong string\nwith multiple\nline breaks."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.