Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Typewriter Effect Text

    Coding
    6
    15
    923
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pobtastic
      pobtastic F last edited by pobtastic

      It's really just a case of setting a "cached" variable and ticking it upwards every x frame. I've not done this specifically but I guess it's similar enough to other things I've written. Something like;

      frame_count = 0
      string = "Really looking forward to playing Steve's Missile Command game"
      tick = 0
      
      loop
        clear()
        printat(0, 0, string[:tick])
        if frame_count % 20 == 0 then
          // Or however you want to do it?
          // This would (hopefully) just cycle it round to zero again
          // but you'd obviously continue on rather than pause here.
          tick = (tick + 1) % len(str)
        endif
        update()
        frame_count += 1
      repeat
      

      Obviously that's completely untested!

      1 Reply Last reply Reply Quote 2
      • lawyerlounge
        lawyerlounge last edited by

        what is the colon before "tick" for?

        printAt(0, 0, string[:tick])
        

        Also, what and how is % used?

        Thankyou!

        pianofire 1 Reply Last reply Reply Quote 1
        • pobtastic
          pobtastic F last edited by pobtastic

          Okay, I just tested it and meh ~ use this instead;

          frame_count = 0
          string = "Really looking forward to playing Steve's Missile Command game"
          tick = 0
          proceed = false
          
          while !proceed loop
            clear()
            printat(0, 0, string[:tick])
            if frame_count % 20 == 0 then
              tick += 1
              if tick == len(string) then
                proceed = true
              endif
            endif
            update()
            frame_count += 1
          repeat
          

          It was close enough :)

          edit: See https://fuzearena.com/forum/topic/70/hints-and-tips/9

          Juggalo_Jesus 1 Reply Last reply Reply Quote 1
          • pianofire
            pianofire Fuze Team @lawyerlounge last edited by pianofire

            @lawyerlounge Have a look at this post to see how you can slice up strings using : https://fuzearena.com/forum/topic/70/hints-and-tips/9

            % is the modulus operator which basically returns the remainder when you divide by the number see https://fuzearena.com/help/view/modulus

            1 Reply Last reply Reply Quote 2
            • pobtastic
              pobtastic F last edited by pobtastic

              Oop! Thanks, I missed the question about the %! The good thing about doing it by frame skipping, is that you can then also add controls in there too, and just or a button press which would speed up the "typing".

              1 Reply Last reply Reply Quote 2
              • lawyerlounge
                lawyerlounge last edited by

                Ok neat I think I understand now. The modulo operation is used to only run this loop when frame_count is a number divisible by 20 with no remainder. so it will print a new letter every 20 frames? so you could even have a button press to have frame_count += 10 to speed up the text.

                Also when you have
                Loop
                clear()
                update()
                repeat
                how many times does that run per second, is it 60fps?

                1 Reply Last reply Reply Quote 2
                • Juggalo_Jesus
                  Juggalo_Jesus @pobtastic last edited by

                  @pobtastic Thank you for this!

                  1 Reply Last reply Reply Quote 0
                  • Martin
                    Martin Fuze Team last edited by

                    The above (% on the number of frames) is how I've always done this kind of thing, but I think this might be the first instance where I might be tempted to try and use a timer instead?

                    1 Reply Last reply Reply Quote 1
                    • Martin
                      Martin Fuze Team last edited by Martin

                      How about this?

                      string message = "Really looking forward to playing Steve's Missile Command game"
                      tick = 0
                      speed = 0.25
                      
                      // Call function 'doTick' every 'speed' seconds, indefinitely
                      tickTimer = setTimer(speed, -1, doTick())
                      
                      loop
                          clear()
                          printat(0, 0, message[:tick])
                          update()
                      repeat
                      
                      function doTick()
                          tick += 1
                          if (tick >= len(message)) then tick = 0 endif
                      return void
                      

                      Nearly always lots of ways to approach the same thing. Usually all just as valid.

                      1 Reply Last reply Reply Quote 5
                      • SteveZX81
                        SteveZX81 F last edited by

                        Thanks for that, I just ..borrowed it..

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post