GMS 2 Speeding up typewriter text effect only when key is pressed

Discussion in 'Programming' started by Falconsoft-Industries, Jul 8, 2018.

  1. Here’s my draw event code
    draw_sprite(self.x+4,self.y+4,spr_message_box)
    If !keyboard_check_pressed(vk_space)
    {
    draw_text(x,y,draw_copy_string(sentences,1,index))
    // 1 is how many characters a second are typed
    }
    If keyboard_check_pressed(vk_space)
    {
    draw_text(x,y,draw_copy_string(sentences,10,index))
    // 10 is how many characters a second are typed
    }
    Will this work?, ‘I know all my other code to handle loops for the typewriter text effect work.’
     
    Last edited by a moderator: Jul 15, 2018
  2. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    It looks like that should work, the best thing to do would be to test it, if it doesnt work post the code block that determines how many characters are typed in a time range and we can see if theres an error there or if it just needs to be modifyed to be made more dynamic.
     
  3. Kyon

    Kyon Member

    Joined:
    Jun 27, 2016
    Posts:
    506
    We have no idea what draw_copy_string() does so we wouldn't know.
    Simply testing it would work though.

    Anyway, I have my own method for typewriter-like text with a way to speed it up, if you need any help just ask :)
     
  4. Thanks that would be great if my solution does not work I will ask you for help... :)
     
  5. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    1,017
    Instead of asking whether it will work, why not test it out first? Then you would have discovered that it would only work for a single frame.
     
  6. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    902
    Your typewriter effect might, but your sprite drawing won't.
    You really need to read up on how to use the draw_sprite function as this is now the second topic where you have posted the incorrect syntax of that function.

    From the manual:
    Code:
    draw_sprite(sprite, subimg, x, y);
    What you tried to do:
    Code:
    draw_sprite(x, y, sprite)
     
    Wraithious likes this.
  7. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    I totally missed that, I was focused on the typewriter script part, yea that code would definatly crash the game on the first draw step it's executed in.
     
  8. Yeah okay I have tried this method but it does not work, also I need help with setting a timeline in gml, for a path for a cutscene object because doing it with direction and speed and image_index changing on collision with non viewable trigger objects only worked once and I need them to be viewable but with image_alpha=0 and when I attempted the paths resource tree it only makes it worst and harder to use, so I am timing the movement patterns I need now, using a timeline resource.
     
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,343
    Your code, if anything, should draw 10 letters at a time every single time you press the spacebar, otherwise it will display one at a time. But you have to keep tapping the space bar. either use a normal keyboard_check() call or use a variable to track when the current dialogue needs to be sped up (and clear the variable at the end of the dialogue).
     
  10. Ah thanks I will give that a try.
    Yes it works thank you...
     
    Last edited by a moderator: Jul 10, 2018
  11. hmmmmm... the new problem is that it replaces the text with the first 10 letters where the start of the first line of text is including adding the typed out text already typed. how to fix?
    Ah I see the solution now all I really needed is this code after drawing the the message box and text, the solution is as follows

    if keyboard_check(vk_space)
    {
    index++
    }
     
    Last edited by a moderator: Jul 15, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice