issue in transition.pause() and transition.resume() in ios

Hi , 

   i had issue on transition.resume after transition.pause call , the issue i’m facing was lag in time on transition.resume . in app i use audio and transition of text object(text highlight). at some point it’s need to be pause and resume after sometimes. it get pause perfectly but when resume the function audio works perfectly but the transition fails.it jumps far to next text object.please need help asap.

Thanks 

FYI , it works perfectly in Corona simulator, but failed in device test.

Post code!

please find the code , and the pause and resume function call should be made  after few sec of time.

Are you going to post your code in this thread?

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here display.setStatusBar(display.HiddenStatusBar) local widget = require "widget" local animationStatus = "resume" local syncSound = require "syncSound" -- Box transition sample --[[local box = display.newRect(0,0,100,100) box.x,box.y = 60,50 transition.to( box , { x = 260 , y = 300 , time = 3000 , transition = easing.continuousLoop , tag = "box" } ) transition.pause("box") local function pausebtnRelease(event) if animationStatus == "resume" then animationStatus = "pause" transition.pause("box") end return true end local function resumebtnRelease(event) if animationStatus == "pause" then animationStatus = "resume" transition.resume("box") end return true end]] -- Text transition local speak\_401 = display.newImageRect( "kAudio.png", 30, 30 ); speak\_401.x = 24; speak\_401.y = 180 speak\_401.alpha = 0 local kwk\_readMeFile = audio.loadSound( "thedream\_5.mp3" ) local s115textbody\_txt = { {start = 0, out = 654.088, dur = 0, name = "There"}, {start = 652.92, out = 1106.11, dur = 0, name = "once"}, {start = 1107.278, out = 1189.039, dur = 0, name = "was"}, {start = 1190.207, out = 1288.32, dur = 0, name = "a"}, {start = 1289.488, out = 1714.645, dur = 0, name = "man"}, {start = 1716.981, out = 2032.345, dur = 0, name = "called"}, {start = 2032.345, out = 2881.491, dur = 0, name = "Ahmad"}, {start = 2881.491, out = 3046.181, dur = 0, name = "who"}, {start = 3045.013, out = 3393.082, dur = 0, name = "lived"}, {start = 3393.082, out = 3622.013, dur = 0, name = "in"}, {start = 3622.013, out = 5214.016, dur = 0, name = "Baghdad."}, {start = 5214.016, out = 5363.522, dur = 0, name = "He"}, {start = 5363.522, out = 5515.364, dur = 0, name = "had", newline = true}, {start = 5515.364, out = 6269.901, dur = 0, name = "four"}, {start = 6269.901, out = 6912.309, dur = 0, name = "wonderful"}, {start = 6912.309, out = 7593.261, dur = 0, name = "children"}, {start = 7593.261, out = 7714.735, dur = 0, name = "and"}, {start = 7713.567, out = 7991.554, dur = 0, name = "a"}, {start = 7991.554, out = 8365.319, dur = 0, name = "loving"}, {start = 8365.319, out = 8852.381, dur = 0, name = "wife,"}, {start = 8851.213, out = 10598.562, dur = 0, name = "Amira."}, {start = 10598.562, out = 11641.599, dur = 0, name = "Together,"}, {start = 11641.599, out = 11945.283, dur = 0, name = "they", newline = true}, {start = 11945.283, out = 12306.199, dur = 0, name = "all"}, {start = 12306.199, out = 12595.867, dur = 0, name = "lived"}, {start = 12595.867, out = 12698.652, dur = 0, name = "in"}, {start = 12698.652, out = 12829.47, dur = 0, name = "a"}, {start = 12829.47, out = 13978.796, dur = 0, name = "broken-down"}, {start = 13978.796, out = 14403.953, dur = 0, name = "green"}, {start = 14405.121, out = 14952.92, dur = 0, name = "house"}, {start = 14952.92, out = 15249.596, dur = 0, name = "under"}, {start = 15249.596, out = 15417.79, dur = 0, name = "a"}, {start = 15417.79, out = 15911.86, dur = 0, name = "carob"}, {start = 15911.86, out = 17065.858, dur = 0, name = "tree."}, {start = 17064.69, out = 18147.439, dur = 0, name = "Everyday,", newline = true}, {start = 18147.439, out = 18692.902, dur = 0, name = "Ahmad"}, {start = 18692.902, out = 18938.185, dur = 0, name = "worked"}, {start = 18938.185, out = 19679.874, dur = 0, name = "long"}, {start = 19679.874, out = 19842.228, dur = 0, name = "and"}, {start = 19842.228, out = 20815.184, dur = 0, name = "hard,"}, {start = 20815.184, out = 21372.327, dur = 0, name = "digging"}, {start = 21372.327, out = 21929.47, dur = 0, name = "ditches"}, {start = 21929.47, out = 22063.792, dur = 0, name = "in"}, {start = 22063.792, out = 22268.194, dur = 0, name = "the"}, {start = 22268.194, out = 22678.167, dur = 0, name = "desert"}, {start = 22678.167, out = 23327.583, dur = 0, name = "soil."}, } local b\_s115textbody, s115textbody = syncSound.addSentence{ x = 39, y = 180, padding = 10, sentence=kwk\_readMeFile, sentenceDir="audio", line=s115textbody\_txt, button=speak\_401, font="CooperBlack", fontColor = {255, 255, 255}, fontSize = 24, fontColorHi = {254, 245, 3}, fadeDuration = 500, wordTouch = false, readDir="leftToRight"} timer.performWithDelay( 1000, function() syncSound.saySentence{sentence=kwk\_readMeFile,line=s115textbody\_txt, button=b\_s115textbody} end) local function pausebtnRelease(event) if animationStatus == "resume" then animationStatus = "pause" syncSound.pauseSenetnce() end return true end local function resumebtnRelease(event) if animationStatus == "pause" then animationStatus = "resume" syncSound.resumeSenetnce() end return true end local pausebtn = widget.newButton({ label = "Pause", fontSize = 30, onRelease = pausebtnRelease, }) pausebtn.x,pausebtn.y = display.contentCenterX , display.contentCenterY + 120 local resumebtn = widget.newButton({ label = "Resume", fontSize = 30, onRelease = resumebtnRelease, }) resumebtn.x,resumebtn.y = display.contentCenterX , pausebtn.y + 70
-- syncSound.lua -- Electric Eggplant's Synchronied Text to Speech framework -- version 2.2 - includes read right to left, fixes highlight -- version 2.3 (1/3/12) - do not play synced when in "I will read" mode (requires kwk\_readMe = 1 to play) -- version 2.4 (2/11/12) - added audio channel to avoid multiple plays -- version 2.5 (3/26/12) - fix issue when user keeps pressing the play button module(..., package.seeall) local fadeInDur = 100 local fadeOutDur = 100 local transele = {} -- Using the sentence table, display the text by creating an object for each word local function displayText(params) local line, x,y,font,fontSize,fontColor,fontColorHi,group, wordTouch = params.line, params.x, params.y, params.font, params.fontSize, params.fontColor, params.fontColorHi, params.group, params.wordTouch local xOffset = 0 local words={} local lineHeight = fontSize\*1.33 local space = fontSize/5 local name = "" local dir = params.sentenceDir .. "\_words/" local readDir = "leftToRight" if params.readDir then readDir = params.readDir end local newX for i = 1,#line do words[i] = display.newText(line[i].name, 0, 0, font, fontSize) words[i]:setFillColor( fontColor[1]/255,fontColor[2]/255,fontColor[3]/255) words[i].alpha = 1 words[i].activeText = display.newText(line[i].name, 0,0, font, fontSize) words[i].activeText:setFillColor( fontColorHi[1]/255,fontColorHi[2]/255,fontColorHi[3]/255) words[i].activeText.alpha = 0 group:insert(words[i],true) group:insert(words[i].activeText,true) if readDir == "leftToRight" then --words[i]:setReferencePoint(display.TopLeftReferencePoint) words[i].anchorX , words[i].anchorY = 0 , 0 --words[i].activeText:setReferencePoint(display.TopLeftReferencePoint) words[i].activeText.anchorX , words[i].activeText.anchorY = 0 , 0 newX = x+xOffset else --words[i]:setReferencePoint(display.TopRightReferencePoint) words[i].anchorX , words[i].anchorY = 1 , 0 --words[i].activeText:setReferencePoint(display.TopRightReferencePoint) words[i].activeText.anchorX , words[i].activeText.anchorY = 1 , 0 newX = x-xOffset end words[i].x = newX words[i].y = y words[i].activeText.x = newX words[i].activeText.y = y --[[REVIEW THIS WHEN ENABLE THE PLAY AUDIO PER WORD --]] -- convert to lower case and remove punctuation from name so we can use it -- to load correct audio file if wordTouch then name = string.lower(string.gsub(line[i].name, "['.,]", "")) print("ignored?") words[i].snd = audio.loadSound(audioDir..name ..".mp3") words[i].id = i -- calculate the duration of each word words[i].dur = line[i].dur if params.addListner then words[i]:addEventListener( "tap", speakWord ) end end --if wordTouch xOffset = xOffset + words[i].width + space if line[i].newline then y = y + lineHeight; xOffset = 0 end end line.soundLength = line[#line].out return words end -- Add a button to start the talking local function displayButton(params) local x,y,w,h,color = params.x, params.y, params.w, params.h, params.color local rect = display.newRect(x, y, w, h) rect:setFillColor(color[1],color[2],color[3]) return rect end function saySentence( params ) if (kwk\_readMe==0) then return else local button = params.button local text = button.text local sentence, line, delay1, delay2, trans1, trans2, chan = params.sentence, params.line, 0,0,fadeInDur,fadeOutDur,params.chan local chan = 32 if params.chan then chan = params.chan end local transOut = button.transOut local transIn = button.transIn local isChannelPlaying = audio.isChannelPlaying(chan) if isChannelPlaying then --nothing else audio.play(sentence, {channel=chan}) end -- fade button so it's not touchable transele[#transele+1] = transition.to(button, { time=trans2, delay=0, alpha=.9 , tag = "textspc" } ) transele[#transele+1] = transition.to(button, { time=trans2, delay=line.soundLength+trans1, alpha=1 , tag = "textspc" } ) local loops = math.floor(line.soundLength/1000\*3.4) if button.animation then button:setSpeed(.2) -- use .4 if we're running at 30fps button:play{startFrame=2, endFrame=button.numChildren, loop=loops} end for i = 1,#line do -- start transition early so it's full red by the time the word is spoken delay1 = line[i].start - trans1 if delay1 \<0 then delay1 = 0 end -- add extra time at the end so we never finish before the fade is complete delay2 = line[i].out + trans2 -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. transele[#transele+1] = transition.to(text[i].activeText, { delay = delay1, alpha = 1, time=trans1 , tag = "textspc" } ) transele[#transele+1] = transition.to(text[i].activeText, { delay = delay2, alpha = 0, time=trans2 , tag = "textspc" } ) -- transOut[i]=transition.dissolve(text[i],text[i].activeText,trans1,delay1) -- transIn[i]=transition.dissolve(text[i].activeText,text[i],trans2,delay2) end end end -- function pauseSenetnce() print("Text highlight pause") audio.pause() --transition.pause("textspc") local v for v=1,#transele,1 do transition.pause( transele[v] ) end v = nil return true end -- function resumeSenetnce() print("Text highlight resume") audio.resume() --transition.resume("textspc") local v for v=1,#transele,1 do transition.resume( transele[v] ) end v = nil return true end -- The button was pressed, so start talking. Highlight each word as it's spoken. local function touchSentence(event) local button = event.target local text = button.text -- trans1 = how long of a fade from normal to highlighted text -- trans2 = how long of a fade back from highlight to normal local sentence, line, delay1, delay2, trans1, trans2 = button.sentence, button.line, 0,0,fadeInDur,fadeOutDur if button.alpha \< 1 then return true end print(chan) local isChannelPlaying = audio.isChannelPlaying(32) if isChannelPlaying then --nothing else audio.play(sentence, {channel=32}) -- fade button so it's not touchable -- simeon -- transition.to(button, { time=trans2, delay=0, alpha=.9 } ) -- simeon -- transition.to(button, { time=trans2, delay=line.soundLength+trans1, alpha=1 } ) local loops = math.floor(line.soundLength/1000\*3.4) if button.animation then button:setSpeed(.2) -- use .4 if we're running at 30fps button:play{startFrame=2, endFrame=button.numChildren, loop=loops} end for i = 1,#line do -- start transition early so it's full red by the time the word is spoken delay1 = line[i].start - trans1 if delay1 \<0 then delay1 = 0 end -- add extra time at the end so we never finish before the fade is complete delay2 = line[i].out + trans2 -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. -- simeon -- transition.to(text[i].activeText, { delay = delay1, alpha = 1, time=trans1 } ) -- simeon -- transition.to(text[i].activeText, { delay = delay2, alpha = 0, time=trans2 } ) -- transition.dissolve(text[i],text[i].activeText,trans1,delay1) -- transition.dissolve(text[i].activeText,text[i],trans2,delay2) end end end -- A word was touched, so say it now. Disabled during speech. function speakWord( event ) local word = event.target local id, snd, dur, dir = word.id, word.snd, word.dur, word.dir local trans = fadeInDur local trans2 = fadeOutDur -- was the sentence button pushed or this word already active? If so, return now. if button1.alpha == 0 or word.alpha ~= 1 then return end -- make sure the duration is at least longer than 2 transition times dur = dur + 2\*trans audio.play(snd) -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. -- simeon -- transition.to(word.activeText, { delay = 0, alpha = 1, time=trans } ) -- simeon -- transition.to(word.activeText, { delay = dur, alpha = 0, time=trans2 } ) -- transition.dissolve(word,word.activeText,trans,0) -- transition.dissolve(word.activeText,word,trans,dur) return true end function addSentence(params) local textGroup = display.newGroup() local transTime = 1000 if params.fadeDuration then transTime = params.fadeDuration end local talkButton = params.button local talkButtonAnimation = false if params.talkButtonAnimation and talkButton.numChildren then talkButton.animation = params.talkButtonAnimation end local buttonX if params.buttonX then buttonX = params.buttonX end local buttonY if params.buttonY then buttonY = params.buttonY end local buttonInclude = false -- should the talk button be adjacent to the text? if params.buttonInclude then buttonInclude = params.buttonInclude end local font = "Arial" -- default to Arial if params.font then font = params.font end local fontColor = {0,0,0} -- default to black font if params.fontColor then fontColor = params.fontColor end local fontSize = 24 -- default size is 24 if params.fontSize then fontSize = params.fontSize end local fontColorHi = {255,0,0} -- default to red highlighting font color if params.fontColorHi then fontColorHi = params.fontColorHi end local padding = 20 if params.padding then padding = params.padding end local leftPadding = 0 if buttonInclude then leftPadding = talkButton.width end local fontOffset = 0 if params.fontOffset then fontOffset = params.fontOffset end local backgroundRectAlpha = 0 if params.backgroundRectAlpha then backgroundRectAlpha = params.backgroundRectAlpha end local backgroundRectColor = {255,255,255} if params.backgroundRectColor then backgroundRectColor = params.backgroundRectColor end local readDir = "leftToRight" if params.readDir then readDir = params.readDir end print(readDir) --[[if not escapeButton.isHitTestable then transTime = 0 end -- bring up sentence immeditately since we've escaped out of the intro --]] talkButton:addEventListener( "tap", touchSentence ) talkButton.sentence = params.sentence -- name of audio file to use talkButton.line = params.line -- array holding timings and words -- display the text talkButton.text = displayText{line=params.line,sentence=params.sentence,sentenceDir=params.sentenceDir, x=params.x+padding+leftPadding,y=params.y+padding+fontOffset, font=font, fontColor=fontColor, fontSize=fontSize, addListner=true, fontColorHi=fontColorHi, group=textGroup, wordTouch=params.wordTouch, readDir=readDir} talkButton.transIn = {} talkButton.transOut = {} if backgroundRectAlpha \> 0 then local backgroundRect = display.newRoundedRect(params.x, params.y, textGroup.width + padding\*2 + leftPadding, textGroup.height + padding\*2, 12) backgroundRect:setFillColor(backgroundRectColor[1],backgroundRectColor[2],backgroundRectColor[3]) backgroundRect.alpha = backgroundRectAlpha textGroup:insert(1,backgroundRect) end if buttonInclude then textGroup:insert(talkButton,true) --talkButton:setReferencePoint(display.CenterLeftReferencePoint) talkButton.anchorX , talkButton.anchorY = 0 , 0.5 talkButton.x, talkButton.y = params.x+10,params.y+backgroundRect.height/2 end textGroup.alpha = 0 transition.to( textGroup, { time=transTime, alpha=1 } ) return talkButton, textGroup end

FYI , it works perfectly in Corona simulator, but failed in device test.

Post code!

please find the code , and the pause and resume function call should be made  after few sec of time.

Are you going to post your code in this thread?

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here display.setStatusBar(display.HiddenStatusBar) local widget = require "widget" local animationStatus = "resume" local syncSound = require "syncSound" -- Box transition sample --[[local box = display.newRect(0,0,100,100) box.x,box.y = 60,50 transition.to( box , { x = 260 , y = 300 , time = 3000 , transition = easing.continuousLoop , tag = "box" } ) transition.pause("box") local function pausebtnRelease(event) if animationStatus == "resume" then animationStatus = "pause" transition.pause("box") end return true end local function resumebtnRelease(event) if animationStatus == "pause" then animationStatus = "resume" transition.resume("box") end return true end]] -- Text transition local speak\_401 = display.newImageRect( "kAudio.png", 30, 30 ); speak\_401.x = 24; speak\_401.y = 180 speak\_401.alpha = 0 local kwk\_readMeFile = audio.loadSound( "thedream\_5.mp3" ) local s115textbody\_txt = { {start = 0, out = 654.088, dur = 0, name = "There"}, {start = 652.92, out = 1106.11, dur = 0, name = "once"}, {start = 1107.278, out = 1189.039, dur = 0, name = "was"}, {start = 1190.207, out = 1288.32, dur = 0, name = "a"}, {start = 1289.488, out = 1714.645, dur = 0, name = "man"}, {start = 1716.981, out = 2032.345, dur = 0, name = "called"}, {start = 2032.345, out = 2881.491, dur = 0, name = "Ahmad"}, {start = 2881.491, out = 3046.181, dur = 0, name = "who"}, {start = 3045.013, out = 3393.082, dur = 0, name = "lived"}, {start = 3393.082, out = 3622.013, dur = 0, name = "in"}, {start = 3622.013, out = 5214.016, dur = 0, name = "Baghdad."}, {start = 5214.016, out = 5363.522, dur = 0, name = "He"}, {start = 5363.522, out = 5515.364, dur = 0, name = "had", newline = true}, {start = 5515.364, out = 6269.901, dur = 0, name = "four"}, {start = 6269.901, out = 6912.309, dur = 0, name = "wonderful"}, {start = 6912.309, out = 7593.261, dur = 0, name = "children"}, {start = 7593.261, out = 7714.735, dur = 0, name = "and"}, {start = 7713.567, out = 7991.554, dur = 0, name = "a"}, {start = 7991.554, out = 8365.319, dur = 0, name = "loving"}, {start = 8365.319, out = 8852.381, dur = 0, name = "wife,"}, {start = 8851.213, out = 10598.562, dur = 0, name = "Amira."}, {start = 10598.562, out = 11641.599, dur = 0, name = "Together,"}, {start = 11641.599, out = 11945.283, dur = 0, name = "they", newline = true}, {start = 11945.283, out = 12306.199, dur = 0, name = "all"}, {start = 12306.199, out = 12595.867, dur = 0, name = "lived"}, {start = 12595.867, out = 12698.652, dur = 0, name = "in"}, {start = 12698.652, out = 12829.47, dur = 0, name = "a"}, {start = 12829.47, out = 13978.796, dur = 0, name = "broken-down"}, {start = 13978.796, out = 14403.953, dur = 0, name = "green"}, {start = 14405.121, out = 14952.92, dur = 0, name = "house"}, {start = 14952.92, out = 15249.596, dur = 0, name = "under"}, {start = 15249.596, out = 15417.79, dur = 0, name = "a"}, {start = 15417.79, out = 15911.86, dur = 0, name = "carob"}, {start = 15911.86, out = 17065.858, dur = 0, name = "tree."}, {start = 17064.69, out = 18147.439, dur = 0, name = "Everyday,", newline = true}, {start = 18147.439, out = 18692.902, dur = 0, name = "Ahmad"}, {start = 18692.902, out = 18938.185, dur = 0, name = "worked"}, {start = 18938.185, out = 19679.874, dur = 0, name = "long"}, {start = 19679.874, out = 19842.228, dur = 0, name = "and"}, {start = 19842.228, out = 20815.184, dur = 0, name = "hard,"}, {start = 20815.184, out = 21372.327, dur = 0, name = "digging"}, {start = 21372.327, out = 21929.47, dur = 0, name = "ditches"}, {start = 21929.47, out = 22063.792, dur = 0, name = "in"}, {start = 22063.792, out = 22268.194, dur = 0, name = "the"}, {start = 22268.194, out = 22678.167, dur = 0, name = "desert"}, {start = 22678.167, out = 23327.583, dur = 0, name = "soil."}, } local b\_s115textbody, s115textbody = syncSound.addSentence{ x = 39, y = 180, padding = 10, sentence=kwk\_readMeFile, sentenceDir="audio", line=s115textbody\_txt, button=speak\_401, font="CooperBlack", fontColor = {255, 255, 255}, fontSize = 24, fontColorHi = {254, 245, 3}, fadeDuration = 500, wordTouch = false, readDir="leftToRight"} timer.performWithDelay( 1000, function() syncSound.saySentence{sentence=kwk\_readMeFile,line=s115textbody\_txt, button=b\_s115textbody} end) local function pausebtnRelease(event) if animationStatus == "resume" then animationStatus = "pause" syncSound.pauseSenetnce() end return true end local function resumebtnRelease(event) if animationStatus == "pause" then animationStatus = "resume" syncSound.resumeSenetnce() end return true end local pausebtn = widget.newButton({ label = "Pause", fontSize = 30, onRelease = pausebtnRelease, }) pausebtn.x,pausebtn.y = display.contentCenterX , display.contentCenterY + 120 local resumebtn = widget.newButton({ label = "Resume", fontSize = 30, onRelease = resumebtnRelease, }) resumebtn.x,resumebtn.y = display.contentCenterX , pausebtn.y + 70
-- syncSound.lua -- Electric Eggplant's Synchronied Text to Speech framework -- version 2.2 - includes read right to left, fixes highlight -- version 2.3 (1/3/12) - do not play synced when in "I will read" mode (requires kwk\_readMe = 1 to play) -- version 2.4 (2/11/12) - added audio channel to avoid multiple plays -- version 2.5 (3/26/12) - fix issue when user keeps pressing the play button module(..., package.seeall) local fadeInDur = 100 local fadeOutDur = 100 local transele = {} -- Using the sentence table, display the text by creating an object for each word local function displayText(params) local line, x,y,font,fontSize,fontColor,fontColorHi,group, wordTouch = params.line, params.x, params.y, params.font, params.fontSize, params.fontColor, params.fontColorHi, params.group, params.wordTouch local xOffset = 0 local words={} local lineHeight = fontSize\*1.33 local space = fontSize/5 local name = "" local dir = params.sentenceDir .. "\_words/" local readDir = "leftToRight" if params.readDir then readDir = params.readDir end local newX for i = 1,#line do words[i] = display.newText(line[i].name, 0, 0, font, fontSize) words[i]:setFillColor( fontColor[1]/255,fontColor[2]/255,fontColor[3]/255) words[i].alpha = 1 words[i].activeText = display.newText(line[i].name, 0,0, font, fontSize) words[i].activeText:setFillColor( fontColorHi[1]/255,fontColorHi[2]/255,fontColorHi[3]/255) words[i].activeText.alpha = 0 group:insert(words[i],true) group:insert(words[i].activeText,true) if readDir == "leftToRight" then --words[i]:setReferencePoint(display.TopLeftReferencePoint) words[i].anchorX , words[i].anchorY = 0 , 0 --words[i].activeText:setReferencePoint(display.TopLeftReferencePoint) words[i].activeText.anchorX , words[i].activeText.anchorY = 0 , 0 newX = x+xOffset else --words[i]:setReferencePoint(display.TopRightReferencePoint) words[i].anchorX , words[i].anchorY = 1 , 0 --words[i].activeText:setReferencePoint(display.TopRightReferencePoint) words[i].activeText.anchorX , words[i].activeText.anchorY = 1 , 0 newX = x-xOffset end words[i].x = newX words[i].y = y words[i].activeText.x = newX words[i].activeText.y = y --[[REVIEW THIS WHEN ENABLE THE PLAY AUDIO PER WORD --]] -- convert to lower case and remove punctuation from name so we can use it -- to load correct audio file if wordTouch then name = string.lower(string.gsub(line[i].name, "['.,]", "")) print("ignored?") words[i].snd = audio.loadSound(audioDir..name ..".mp3") words[i].id = i -- calculate the duration of each word words[i].dur = line[i].dur if params.addListner then words[i]:addEventListener( "tap", speakWord ) end end --if wordTouch xOffset = xOffset + words[i].width + space if line[i].newline then y = y + lineHeight; xOffset = 0 end end line.soundLength = line[#line].out return words end -- Add a button to start the talking local function displayButton(params) local x,y,w,h,color = params.x, params.y, params.w, params.h, params.color local rect = display.newRect(x, y, w, h) rect:setFillColor(color[1],color[2],color[3]) return rect end function saySentence( params ) if (kwk\_readMe==0) then return else local button = params.button local text = button.text local sentence, line, delay1, delay2, trans1, trans2, chan = params.sentence, params.line, 0,0,fadeInDur,fadeOutDur,params.chan local chan = 32 if params.chan then chan = params.chan end local transOut = button.transOut local transIn = button.transIn local isChannelPlaying = audio.isChannelPlaying(chan) if isChannelPlaying then --nothing else audio.play(sentence, {channel=chan}) end -- fade button so it's not touchable transele[#transele+1] = transition.to(button, { time=trans2, delay=0, alpha=.9 , tag = "textspc" } ) transele[#transele+1] = transition.to(button, { time=trans2, delay=line.soundLength+trans1, alpha=1 , tag = "textspc" } ) local loops = math.floor(line.soundLength/1000\*3.4) if button.animation then button:setSpeed(.2) -- use .4 if we're running at 30fps button:play{startFrame=2, endFrame=button.numChildren, loop=loops} end for i = 1,#line do -- start transition early so it's full red by the time the word is spoken delay1 = line[i].start - trans1 if delay1 \<0 then delay1 = 0 end -- add extra time at the end so we never finish before the fade is complete delay2 = line[i].out + trans2 -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. transele[#transele+1] = transition.to(text[i].activeText, { delay = delay1, alpha = 1, time=trans1 , tag = "textspc" } ) transele[#transele+1] = transition.to(text[i].activeText, { delay = delay2, alpha = 0, time=trans2 , tag = "textspc" } ) -- transOut[i]=transition.dissolve(text[i],text[i].activeText,trans1,delay1) -- transIn[i]=transition.dissolve(text[i].activeText,text[i],trans2,delay2) end end end -- function pauseSenetnce() print("Text highlight pause") audio.pause() --transition.pause("textspc") local v for v=1,#transele,1 do transition.pause( transele[v] ) end v = nil return true end -- function resumeSenetnce() print("Text highlight resume") audio.resume() --transition.resume("textspc") local v for v=1,#transele,1 do transition.resume( transele[v] ) end v = nil return true end -- The button was pressed, so start talking. Highlight each word as it's spoken. local function touchSentence(event) local button = event.target local text = button.text -- trans1 = how long of a fade from normal to highlighted text -- trans2 = how long of a fade back from highlight to normal local sentence, line, delay1, delay2, trans1, trans2 = button.sentence, button.line, 0,0,fadeInDur,fadeOutDur if button.alpha \< 1 then return true end print(chan) local isChannelPlaying = audio.isChannelPlaying(32) if isChannelPlaying then --nothing else audio.play(sentence, {channel=32}) -- fade button so it's not touchable -- simeon -- transition.to(button, { time=trans2, delay=0, alpha=.9 } ) -- simeon -- transition.to(button, { time=trans2, delay=line.soundLength+trans1, alpha=1 } ) local loops = math.floor(line.soundLength/1000\*3.4) if button.animation then button:setSpeed(.2) -- use .4 if we're running at 30fps button:play{startFrame=2, endFrame=button.numChildren, loop=loops} end for i = 1,#line do -- start transition early so it's full red by the time the word is spoken delay1 = line[i].start - trans1 if delay1 \<0 then delay1 = 0 end -- add extra time at the end so we never finish before the fade is complete delay2 = line[i].out + trans2 -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. -- simeon -- transition.to(text[i].activeText, { delay = delay1, alpha = 1, time=trans1 } ) -- simeon -- transition.to(text[i].activeText, { delay = delay2, alpha = 0, time=trans2 } ) -- transition.dissolve(text[i],text[i].activeText,trans1,delay1) -- transition.dissolve(text[i].activeText,text[i],trans2,delay2) end end end -- A word was touched, so say it now. Disabled during speech. function speakWord( event ) local word = event.target local id, snd, dur, dir = word.id, word.snd, word.dur, word.dir local trans = fadeInDur local trans2 = fadeOutDur -- was the sentence button pushed or this word already active? If so, return now. if button1.alpha == 0 or word.alpha ~= 1 then return end -- make sure the duration is at least longer than 2 transition times dur = dur + 2\*trans audio.play(snd) -- rather than using dissolve, which looks choppy, let's just fade in the highlight -- text that's sitting on top of the black text. -- simeon -- transition.to(word.activeText, { delay = 0, alpha = 1, time=trans } ) -- simeon -- transition.to(word.activeText, { delay = dur, alpha = 0, time=trans2 } ) -- transition.dissolve(word,word.activeText,trans,0) -- transition.dissolve(word.activeText,word,trans,dur) return true end function addSentence(params) local textGroup = display.newGroup() local transTime = 1000 if params.fadeDuration then transTime = params.fadeDuration end local talkButton = params.button local talkButtonAnimation = false if params.talkButtonAnimation and talkButton.numChildren then talkButton.animation = params.talkButtonAnimation end local buttonX if params.buttonX then buttonX = params.buttonX end local buttonY if params.buttonY then buttonY = params.buttonY end local buttonInclude = false -- should the talk button be adjacent to the text? if params.buttonInclude then buttonInclude = params.buttonInclude end local font = "Arial" -- default to Arial if params.font then font = params.font end local fontColor = {0,0,0} -- default to black font if params.fontColor then fontColor = params.fontColor end local fontSize = 24 -- default size is 24 if params.fontSize then fontSize = params.fontSize end local fontColorHi = {255,0,0} -- default to red highlighting font color if params.fontColorHi then fontColorHi = params.fontColorHi end local padding = 20 if params.padding then padding = params.padding end local leftPadding = 0 if buttonInclude then leftPadding = talkButton.width end local fontOffset = 0 if params.fontOffset then fontOffset = params.fontOffset end local backgroundRectAlpha = 0 if params.backgroundRectAlpha then backgroundRectAlpha = params.backgroundRectAlpha end local backgroundRectColor = {255,255,255} if params.backgroundRectColor then backgroundRectColor = params.backgroundRectColor end local readDir = "leftToRight" if params.readDir then readDir = params.readDir end print(readDir) --[[if not escapeButton.isHitTestable then transTime = 0 end -- bring up sentence immeditately since we've escaped out of the intro --]] talkButton:addEventListener( "tap", touchSentence ) talkButton.sentence = params.sentence -- name of audio file to use talkButton.line = params.line -- array holding timings and words -- display the text talkButton.text = displayText{line=params.line,sentence=params.sentence,sentenceDir=params.sentenceDir, x=params.x+padding+leftPadding,y=params.y+padding+fontOffset, font=font, fontColor=fontColor, fontSize=fontSize, addListner=true, fontColorHi=fontColorHi, group=textGroup, wordTouch=params.wordTouch, readDir=readDir} talkButton.transIn = {} talkButton.transOut = {} if backgroundRectAlpha \> 0 then local backgroundRect = display.newRoundedRect(params.x, params.y, textGroup.width + padding\*2 + leftPadding, textGroup.height + padding\*2, 12) backgroundRect:setFillColor(backgroundRectColor[1],backgroundRectColor[2],backgroundRectColor[3]) backgroundRect.alpha = backgroundRectAlpha textGroup:insert(1,backgroundRect) end if buttonInclude then textGroup:insert(talkButton,true) --talkButton:setReferencePoint(display.CenterLeftReferencePoint) talkButton.anchorX , talkButton.anchorY = 0 , 0.5 talkButton.x, talkButton.y = params.x+10,params.y+backgroundRect.height/2 end textGroup.alpha = 0 transition.to( textGroup, { time=transTime, alpha=1 } ) return talkButton, textGroup end