Sprite for choices system

Discussion in 'Programming' started by SpaceKill, Oct 12, 2019 at 1:10 AM.

  1. SpaceKill

    SpaceKill Member

    Joined:
    Apr 3, 2019
    Posts:
    18
    Hello. Can someone tell me how to add a custom sprite when I have a choice selected.
    Like in Undertale when you have a choice selected you can see your soul next to it like in this image
    [​IMG]
     
  2. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    377
    Exactly how it's coded hinges entirely on how you have your dialogue system coded. I can't really give specifics without seeing any of your underlying code, but here's a very simple example of what it would look like.
    Code:
    var optionTextX, cursorXOffset;
    optionTextX[0] = 32;
    optionTextX[1] = 128;
    cursorXOffset = -16;
    draw_sprite(spr_cursor, 0, optionTextX[selectedOption]+cursorXOffset, optionTextY);
     
    DaMuffin likes this.
  3. SpaceKill

    SpaceKill Member

    Joined:
    Apr 3, 2019
    Posts:
    18
    Well it's not exactly a dialogue system It's for the game's game over screen and I wanted to have a sprite next to my button
    This is my code
    menu_x = x;
    menu_y = y;
    button_h = 32;
    button[0] = "Yes"
    button[1] = "Do not"
    buttons = array_length_1d(button);
    menu_index = 0
    last_selected = 0;
    Step event:
    menu_move = keyboard_check_pressed(vk_left) - keyboard_check_pressed(vk_right);

    menu_index += menu_move;

    if (menu_index < 0) menu_index = buttons - 1;
    if (menu_index > buttons -1) menu_index = 0;
    if (menu_index != last_selected) audio_play_sound(Menu_Scroll,1,false);
    last_selected = menu_index;

    Draw event:
    var i = 0;
    draw_set_font(GameOver)
    draw_set_halign(fa_middle)
    draw_set_color(c_white)

    repeat(buttons) {
    draw_set_color(c_white);
    if (menu_index== i) draw_set_color (c_red);
    draw_text (menu_x, menu_y + button_h * i, button);
    i++;
    }

    Key press:
    switch (menu_index) {
    case 0:
    room_goto(room3)
    break;
    case 1:
    room_goto(room1)
    break;
    }
     
  4. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    377
    Looks like you've almost got a grasp of it! What you'll want to focus on is this section right here:
    It appears that your menu is being drawn like this:
    Code:
    [>] Yes
    [ ] Do not
    Instead of like this:
    Code:
    [>] Yes       [ ] Do not
    If this is the case, simply handle changing the position you're drawing the cursor sprite in the same way you're changing the position of the text being drawn.

    Code:
    //cursor_x_offset is how far to the left of the text the cursor is to be drawn
    var cursor_x_offset = -16;
    repeat(buttons) {
      draw_set_color(c_white);
      if (menu_index== i) {
        draw_set_color (c_red);
        //You may have to fine-tune the position of the cursor sprite to get it to show up exactly where you want
        draw_sprite(spr_cursor, 0, menu_x + cursor_x_offset, menu_y + button_h * i);
      }
      draw_text (menu_x, menu_y + button_h * i, button[i]);
      i++;
    }
    
    As a friendly reminder, if you want your code formatted on the forums like I've been doing it, just put your code inside code brackets like this:
    [_code_]var x = 1;[_/code_]
    Without the underscores the underscores it becomes
    Code:
    var x = 1;
    And it's much easier to read.
     
  5. SpaceKill

    SpaceKill Member

    Joined:
    Apr 3, 2019
    Posts:
    18
    I actually wanted the text to be shown like you said from left to right but I don't know how to make it look that way.
    Can you tell me how ?
     

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