Text which appears gradually

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: Text which appears gradually

Post 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
obey
zingo
Citizen
Posts: 55
Joined: Mon Jan 16, 2023 7:34 am

Re: Text which appears gradually

Post by zingo »

Thanks BrotSagtMist, that approach works great. Maybe others can use this as well.
User avatar
dusoft
Party member
Posts: 711
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Text which appears gradually

Post 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)
tourgen
Citizen
Posts: 53
Joined: Sat Mar 18, 2023 12:45 am

Re: Text which appears gradually

Post by tourgen »

Talkies does this as well, if you would like to look through another way of doing it.

https://github.com/tanema/talkies
zingo
Citizen
Posts: 55
Joined: Mon Jan 16, 2023 7:34 am

Re: Text which appears gradually

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests