Okay a couple of questions in summary:
- can you iterate over the properties of an object?
- can you change the font of a text object once it has been created?
Detail 1:
How do I iterate through object properties? Several places in the API docs imply that objects are just fancy tables, but that doesn’t appear to be fully accurate.
local textObject = display.newText( “My Logo!”, 0, 0, nil, 24 )
for i,v in ipairs(textObject) do
print(i,v)
end
Detail 2:
Say i want to change the font of a text object, and just for kicks, it’s part of a group.
Is there a better way than this to do it? There doesn’t appear to be a :setFont method.
local textObject = display.newText( “My Logo!”, 0, 0, nil, 24 )
textObject:setReferencePoint (display.TopLeftReferencePoint)
textObject.x = ( display.stageWidth - textObject.width ) / 2
textObject.y = 125
textObject:setTextColor( 155,155,255 )
local group = display.newGroup()
group:insert(textObject)
group:setReferencePoint (group.CenterReferencePoint)
local function randomizeFont()
fonts = native.getFontNames()
f = math.random(1,table.maxn(fonts))
group:remove(textObject)
textObject:setReferencePoint (display.TopLeftReferencePoint)
textObject = display.newText( textObject.text, textObject.x, textObject.y, fonts[f], textObject.size)
textObject:setReferencePoint (display.CenterReferencePoint)
group:insert(textObject)
end [import]uid: 5494 topic_id: 576 reply_id: 300576[/import]