I am working on a simple RPG-style text chat. I am having some issues with control the line of the text so I didn’t restrict on height yet.
local HEIGHT = display.contentHeight
local WIDTH = display.contentWidth
local textBlocks = {
{"Kid", "Look, a robot!"},
{"Abe", "BLEEP-BLOOP. I am an Autonomous Botanical Engineer. You can call me ABE."},
{"Kid", "Hi Abe. Meet Frosty the Snowman."},
{"Frosty", "Happy Birthday!"},
{"Abe", "BEEP-BIP. Hello, Frosty."},
{"Abe", "Does this frog belong to you?"},
{"Frog", "Ribbit..."},
{"Kid", "No I've never seen him before. Aren't you cold frog?"},
{"Frog", "Ribbit..."}
}
local SPEAKER = 0;
local TEXT = 1;
local \_currentTextBlockIndex=0;
local \_currentTextBlock = "Aside: The fact that keys are references, and strings can be used, tells us something about Lua's internals. We must be referring to the same string when we get and set the value or table string keys wouldn't work! Strings are not duplicated in Lua internally, so when you reference a string with the same value you are referring to the same string. ";
local displayText = display.newText("Unknown:", 10, 300, 300 ,0, native.systemFont, 20)
displayText:setTextColor(255, 255, 255)
local abc = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
local displayCompareText = display.newText(abc, 350, 300, 300 ,0, native.systemFont, 20)
displayCompareText:setTextColor(0,102,204)
displayCompareText.text = \_currentTextBlock
local function nextTextBlock()
print(\_currentTextBlockIndex)
local function addListener()
displayNextButton:removeEventListener("tap", nextTextBlock);
displayText.text = "";
\_currentTextBlockIndex = \_currentTextBlockIndex + 1;
\_currentTextBlock = textBlocks[\_currentTextBlockIndex][2];
--characterIcon.gotoAndStop(\_textBlocks[\_currentTextBlockIndex][SPEAKER]);
Runtime:addEventListener("enterFrame",updateText)
displayNextButton:addEventListener("tap", fillText);
end
timer.performWithDelay( 1, addListener )
end
function fillText(event)
print("filltext" .. \_currentTextBlockIndex)
displayText.text = \_currentTextBlock;
Runtime:removeEventListener("enterFrame", updateText);
if(\_currentTextBlockIndex \< #textBlocks) then
local function addListener()
displayNextButton:removeEventListener("tap", fillText);
displayNextButton:addEventListener("tap", nextTextBlock);
end
timer.performWithDelay( 1, addListener )
end
end
function updateText(e)
if(#displayText.text \< #\_currentTextBlock) then
displayText.text = string.sub(\_currentTextBlock , 0, #displayText.text+1);
else
--Runtime:removeEventListener("enterFrame", updateText);
fillText();
end
end
displayNextButton = display.newImage( "Button.png" )
displayNextButton.x = 720
displayNextButton.y = 450
displayNextButton:addEventListener("tap", fillText);
Runtime:addEventListener("enterFrame",updateText)
How can I fix the first line of displayText.text at y = 300 ? [import]uid: 111309 topic_id: 22193 reply_id: 88542[/import]