GMS 2 Font size change not working correctly

Discussion in 'Programming' started by gameon, Jun 13, 2019 at 11:42 AM.

  1. gameon

    gameon Member

    Joined:
    Feb 9, 2019
    Posts:
    17
    I created my own fonts using different sizes within a for loop and the font_add function. The idea was to have the font sizes equal the name then you could use a font by the size or use "+" or "-" to move up or down (respectively) in size. The code looks like this:

    Create:
    Code:
    // Create our font size range 8-48.
    minsize = 8;
    maxsize = 48;
    
    // Create our font with inconsolta. Sizes and names are the same 8-48.
    var myfont = working_directory + "Inconsolata.otf"
    for(i = minsize; i < maxsize; i++)
    {
     font_add(myfont, i, false, false, 32, 127)
    }
    
    // The variable "font" sets our font size. We will start at 12
    font = 12;
    In Keypress(Any) Script:
    Code:
    key = keyboard_key;
    
    if (line < 100 && !keyboard_check (vk_control))
    {
      if (string_count(chr(key), keys) == 1 || key > 127)
     {   
      blink = true; alarm[0] = blink_speed;
      cursx += wid; pos++;
    
      txt[line] = string_insert(keyboard_lastchar, txt[line], pos)
     }
    }
    
    if (key != vk_control && keyboard_key != vk_alt){
    switch(key){
    
    case vk_add:
     font++;
     if (font > maxsize) {font = minsize;}
     break;
    
     case vk_subtract:
     font--;
     if (font < minsize) {font = maxsize}
    break;
    }}
    
    When I use the "-" key it will get smaller but then will skip to the last size sometimes. While the "+" key doesn't seem to work at all. Any advice on how to approach this better?

    EDIT: break statements are in my original code just didnt copy over, so I added them.
     
    Last edited: Jun 14, 2019 at 8:39 AM
  2. Azenris

    Azenris Member

    Joined:
    Oct 30, 2016
    Posts:
    50
    you are missing breaks in the case

    so on an add, it runs both the add and subtract code, leaving it the same
     
  3. gameon

    gameon Member

    Joined:
    Feb 9, 2019
    Posts:
    17
    That's interesting must not have copied over. Breaks are in my code. Not only did I double check but its the first thing I do by typing:

    case:
    break;

    Anyway, with being real numbers I had a revelation that perhaps they are being confused with the GMs array resource structure in which I just learned.
     
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,644
    Okay, I suspect this is because you have no alarm to control the input speed? Normally, when dealing with input, I set an alarm and then check if it's counted down before accepting further input. So you'd have Alarm[0] - ofr example - with simply a comment like "// Input Alarm" (if you don't have at least a comment in there then the alarm won't count down), and then in your code you'd have something like

    Code:
    if alarm[0] < 0
    {
    // Input code here
    }
    This will prevent input seemingly "skip" values. This may also be the issue with the "+" section, as it's skipping up so quick that it goes back to the smaller size again (as your code looks fine otherwise).
     
  5. gameon

    gameon Member

    Joined:
    Feb 9, 2019
    Posts:
    17
    @Nocturne Brilliant! That solved most of it.

    However, the sizes didn't quite add up so I tried what I had said previously by running:
    Code:
    font = 0;    //Minimum font size 8?
    font = 40;  //Maximum = 40?
    
    Both were closer to the correct size in relation to the text box size, in this case around 8 and 48. Also another big hint, why I tested this in the first place was the fact that before I wrote the above test code the sizes actually changed after 39. In an array 39 is the 40th "place" which happens to be the max size above with my theory.
    Okay on to string values?
     

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