Page 2 of 2

Re: Text which appears gradually

Posted: Sat Jul 08, 2023 12:18 am
by BrotSagtMist
Lovely riddle in the evening.
My approach:

Code: Select all

C={{1,1,1,1},{1,0,0,1},{1,1,1,1},{0,1,0,1},{.2,.5,.9},{1,.1,1}}
Text = {'This text is',' red ','and then white.',"and green"," and whatever\n","NRNSSNRSNRSZNZrtineaortdaeonrtdeiaondtreatnrdodtrenaotndr"}
Speed=10

T=0
Position1=1
Position2=0
TT={C[1],""}
function love.update(dt)
 T=T+dt*Speed
 if T>1 then 
  T=T-1 
  Position2=Position2+1
  if Position2>#Text[Position1] then
   Position1=Position1+1
   Position2=1
   if not C[Position1] then
    love.update=nil
    return
   end
   table.insert(TT,C[Position1])
   table.insert(TT,"")
  end
  TT[Position1*2]=TT[Position1*2].. string.sub(Text[Position1],Position2,Position2)
 end
end
function love.draw()
 love.graphics.print (TT,10,0)
end

Re: Text which appears gradually

Posted: Sat Jul 08, 2023 12:51 am
by zingo
Thanks BrotSagtMist, that approach works great. Maybe others can use this as well.

Re: Text which appears gradually

Posted: Sat Jul 08, 2023 10:37 am
by dusoft
Recommended: https://github.com/sysl-dev/SYSL-Text
(and yes, you can study the code as well, if you don't use it)

Re: Text which appears gradually

Posted: Sat Jul 08, 2023 1:03 pm
by tourgen
Talkies does this as well, if you would like to look through another way of doing it.

https://github.com/tanema/talkies

Re: Text which appears gradually

Posted: Sun Jul 09, 2023 3:30 am
by zingo
Thank you everyone. I'll take a look at those examples as well, as I do intend to eventually have some kind of dialogue system in whatever kind of game I make in the future. At the moment, I'm not entirely sure what I want to do (possibly either a platformer, or a classic 'top down' rpg), so I'm just kind of working on various independent aspects I'd imagine any kind of game would have, and attempting to make those adaptable and modular.