• 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!

GameMaker Character Portraits Overlapping Each Other?

J

justloveme94

Guest
Hello everyone,

I am currently trying to set up a dialogue system with unique character portraits for each NPC. I was struggling with how to approach drawing multiple sprites. So far I have settled on a 1d array. The only issue I am having now is that the sprites are overlapping each other and I can't quite seem to fix it. Any help is appreciated, thanks!

CREATE Event of obj_textbox
Code:
character_portraits[0] = spr_portrait_emily;
character_portraits[1] = spr_portrait_jude;
DRAW GUI of obj_textbox
Code:
//Draw Portrait
for(var i = 0; i < array_length_1d(character_portraits); i += 1){
    draw_sprite(character_portraits[i], portrait_index, port_x, port_y);
}
CREATE Event of obj_npc_jude
Code:
character_portraits = 1;
CREATE Event of obj_npc_emily
Code:
character_portraits = 0;
 

Sabnock

Member
you need to add spacing to the draw_spite(); so

draw_sprite(character_portraits, portrait_index, port_x + i * sprite_width, port_y);

for instance
 
The problem is the for loop in your draw event. You're essentially telling your textbox to draw every portrait in your array. What you want to do is pass the character_portraits variable from your NPC to the textbox when it is created. I'm assuming that the npc is creating the textbox when you press a key. When you create your textbox, store its id as a variable by putting something like mytextbox = before the function creating the textbox. Then you can do the following:

Code:
//In NPC event that creates the Textbox
mytextbox.portrait = character_portraits;

//In the Textbox Create Event
portrait = 0; //This is going to be overwritten by the NPC

//In the Textbox DRAW GUI Event
draw_sprite(character_portraits[portrait],portrait_index, port_x,port_y);
 
J

justloveme94

Guest
The problem is the for loop in your draw event. You're essentially telling your textbox to draw every portrait in your array. What you want to do is pass the character_portraits variable from your NPC to the textbox when it is created. I'm assuming that the npc is creating the textbox when you press a key. When you create your textbox, store its id as a variable by putting something like mytextbox = before the function creating the textbox. Then you can do the following:

Code:
//In NPC event that creates the Textbox
mytextbox.portrait = character_portraits;

//In the Textbox Create Event
portrait = 0; //This is going to be overwritten by the NPC

//In the Textbox DRAW GUI Event
draw_sprite(character_portraits[portrait],portrait_index, port_x,port_y);
Sorry for the late reply! I started playing around with getting the instructions to work but then I got busy. I think I need some clarification.So currently I have a separate textbox object that creates the textbox when each individual separate NPC object is interacted with. I think I am messing up with the NPC's passing their individual variables. I do not understand the instructions regarding storing the object's id as variable before the function creating the textbox. Is it supposed to go in the textbox's create event? Could you also explain the mytextbox.portrait = character_portraits? I apologize for my confusion. I feel I am so close to getting it working properly.
 
For clarification's sake, how/when are you creating your textbox object? If you're creating it through code in another object, when you put instance_create_layer(obj_textbox,whatever,whatever) you can put something like textbox = (or in the example I gave you mytextbox =) before it. This stores the instance id of the created object (in this case your textbox object) as a variable within the object creating it. You can use this to change variables in the textbox object from within the object creating it.

My example assumes you're creating the textbox using code within the NPC object. In this case I was using mytextbox as the variable storing the textbox's instance id. mytextbox.portrait would reference a variable called portrait within the textbox object (which you'd have to initialize in the textbox object's create event, something I should have clarified before), and setting it to equal character_portraits (the variable you set in the NPC object) lets you reference that specific character's portrait sprite in the textbox's character_portraits array.

Hope that helps.
 
Top