SOLVED Hi. I am trying to code a score and lives ui for the top left hand corner of the screen. It's not working.

SlFinn

Member
Hi. Basically i have coded a ui for the player's score and lives. Yet i am having 2 problems with the outcome when i press play.

The first problem is that the string SCORE and the string LIVES are on top of each other (i am assuming the same x and y coordinates) and are not how they should be, which is one word underneath the other.
The second problem is i am unsure how to make sure that the SCORE and LIVES stays in the top left hand corner of the screen (in the viewport i would like it to always show them in the top left hand corner after i press play).
This is the code i have used so far. I'd appreciate it if you could tell me what i need to add to it to fix these two problems. Ok, here's the code:

The create Event for my ui:

GML:
score = 0;
lives = 3;
The Draw Event for my ui:

Code:
draw_text(20, 20, "SCORE: " + string(score));

draw_text(20, 20, "LIVES: " + string(lives));

draw_set_font(space_font);
Please help me i would appreciate it so much! Thank you for taking the time to read this.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
You are drawing them at the same coordinates, so it's no wonder they draw on top of each other. Y9ou would need to set them to draw at different coordinates, for example:

draw_text(20, 20, "SCORE: " + string(score));
draw_text(20, 40, "LIVES: " + string(lives));


Also, as has been mentioned, you'll want to move this into the Draw GUI event rather than the normal Draw event. With the draw event, if you have a view camera active, then you'll need to offset all the coordinates by the camera position to keep the text in view. However, the GUI events are like a layer on top of the main camera view and are not affected by it. Check the manual for more details.
 

SlFinn

Member
You are drawing them at the same coordinates, so it's no wonder they draw on top of each other. Y9ou would need to set them to draw at different coordinates, for example:

draw_text(20, 20, "SCORE: " + string(score));
draw_text(20, 40, "LIVES: " + string(lives));


Also, as has been mentioned, you'll want to move this into the Draw GUI event rather than the normal Draw event. With the draw event, if you have a view camera active, then you'll need to offset all the coordinates by the camera position to keep the text in view. However, the GUI events are like a layer on top of the main camera view and are not affected by it. Check the manual for more details.
oopsie. Lol thank you for helping me correct my mistake! :)
 
Top