• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Sprite for choices system

S

SpaceKill

Guest
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
 
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);
 
S

SpaceKill

Guest
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;
}
 
Looks like you've almost got a grasp of it! What you'll want to focus on is this section right here:
Code:
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++;
}
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.
 
S

SpaceKill

Guest
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 ?
 
Top