Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do I make text disappear and be replaced by other text

Hey guys, I'm working on a game and I'm wanting to have a guy talking in the background to distract you, but I'm wanting to use text and not sound. I don't want to just have a huge line of really tiny words above him so I was wondering if there is any way to make text disappear and have other text take it's place.

Comments

  • dave1707dave1707 Mod
    Posts: 7,470

    @J-la Put your text in a table and display one entry after the other. You can control the speed at which each entry is shown. You can put as many or as few words in each entry.

  • dave1707dave1707 Mod
    edited October 2016 Posts: 7,470

    @J-la Here's an example.

    displayMode(FULLSCREEN)
    
    function setup()
        rectMode(CENTER)
        tab={}
        table.insert(tab,"Hey guys, I'm working on a game")
        table.insert(tab,"and I'm wanting to have a guy talking")
        table.insert(tab,"in the background to distract you,")
        table.insert(tab,"but I'm wanting to use text and not sound.")
        table.insert(tab,"I don't want to just have a huge line")
        table.insert(tab,"of really tiny words above him")
        table.insert(tab,"so I was wondering if there is any way")
        table.insert(tab,"to make text disappear")
        table.insert(tab,"and have other text take it's place.")
        xx=1
        cnt=0
        fontSize(30)
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        rect(WIDTH/2,HEIGHT-100,600,50)
        fill(255,0,0)
        text(tab[xx],WIDTH/2,HEIGHT-100)
        cnt=cnt+1
        if cnt>180 then
            cnt=0
            xx=xx+1
            if xx>9 then
                xx=1
            end
        end
    end
    
  • dave1707dave1707 Mod
    edited October 2016 Posts: 7,470

    @J-la If you don't want to create a table, you can put the text in a string and display it. In this example, you can set the number of words to show and the number of seconds between displays.

    EDIT: Modified the code below.

    displayMode(FULLSCREEN)
    
    function setup()
        rectMode(CENTER)
        str="Hey guys, I'm working on a game and I'm wanting to have a guy talking in the background to distract you, but I'm wanting to use text and not sound. I don't want to just have a huge line of really tiny words above him so I was wondering if there is any way to make text disappear and have other text take it's place."    
        fontSize(30)
        cnt=9999
        str2=""
        st=0
        words=7
        seconds=1
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        rect(WIDTH/2,HEIGHT-100,600,50)
        fill(255,0,0)
        text(str2,WIDTH/2,HEIGHT-100)
        cnt=cnt+1
        if cnt>seconds*60 then
            cnt=0  
            readString()     
        end
    end
    
    function readString()
        str2=""
        c=0
        st=st+1
        for en=st,#str do
            v=string.sub(str,en,en)
            if v==" " then
                c=c+1
                if c>=words then
                    str2=string.sub(str,st,en)
                    st=en                 
                    return              
                end
            end
        end 
        str2=string.sub(str,st,#str) 
        st=0
    end
    
  • Posts: 9

    THANK YOU SO MUCH!!! I literally had no idea how to do it.

Sign In or Register to comment.