Hello!
I’ve been studying the Match the Letter sample code. I’m confused about this function I have inserted below.
Specifically, what is going on in this line:
local char = factory.newLetterButton(char,wordColor).graphics
and this line
wordGraphic:insert(char)
What is the .graphics thing, and is “wordGraphic” a table? I didn’t see it defined anywhere else in the code…
Maybe i’m missing something though, I’m newbie! Any help appreciated!
FROM: Match the Letter (kids’ game) by John Polacek
https://github.com/johnpolacek/Match-The-Letter-Game
[code]
function showWord()
– THIS SHOWS THE ENTIRE WORD ONCE YOU HAVE ANSWERED THE QUESTION
– get word from content data object
– see content.lua, playOrder is random. currQuestion starts at 0.
local word = content[playOrder[currQuestion]].word
– make word graphic and transition in
wordGraphic = display.newGroup()
local wordColor = factory.getRandomColors(1)[1]
– Delay is the delay after each letter pops on the screen
local animationDelay = 500
– 1 to end of word
for i=1,string.len(word) do
– store the single letter into a variable
local char = word:sub(i,i)
if char == " " then
– space (just doing nothing, and loop will go to next i)
else
local char = factory.newLetterButton(char,wordColor).graphics
wordGraphic:insert(char)
char.x = (char.width * .72) * (i-1)
local charDelay = (i-1) * animationDelay
transition.from(char, {time = 400, delay = charDelay, y=centerY+char.height, transition=easing.easeOutElastic})
end
end
wordGraphic.x = centerX - wordGraphic.width/2
wordGraphic.y = centerY - wordGraphic.height/2
timer.performWithDelay(wordGraphic.numChildren * animationDelay + 1000, onWordComplete)
end
[/code] [import]uid: 191855 topic_id: 33387 reply_id: 333387[/import]