Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create Event
- /// @description Insert description here
- // You can write your code in this editor
- //Speed at which text is drawn to the screen every frame
- txtSpeed = 1;
- //How many letters to draw
- txtLetters = 0;
- //The whole string we actually want to draw
- txtString = "I made some modifications to your sign post code and now I can parse any string that is over a specific width and add line breaks! It will only add line breaks where it finds a space! Additionally the size of the text box is dynamic! Thanks Shaun!";
- //Get the length of the string
- txtLength = string_length(txtString);
- //Equal to some of the text
- txtCurrent = "";
- //Declare some Variable
- txtWidth = 0;
- txtMaxWidth = 200;
- txtHeight= 0;
- txtBorder = 10;
- charNum = 0;
- parsed = false;
- //Step Event
- /// @description Insert description here
- // You can write your code in this editor
- txtLetters += txtSpeed;
- txtCurrent = string_copy(txtString, 1, floor(txtLetters));
- draw_set_font(fntXolonium);
- txtWidth = string_width(txtCurrent);
- if ((txtWidth > txtMaxWidth) && (parsed == false)){
- //This will give us the character position to insert a line break
- charNum = string_length(txtCurrent);
- //Using the string length get the number of line breaks we need to add
- var numLineBreaks = string_length(txtString) div charNum;
- var lineBreakPosition = 0;
- var tempPos = 0;
- for (var i = 1; i <= numLineBreaks; i++) {
- lineBreakPosition = charNum * i;
- tempPos = lineBreakPosition;
- if (string_char_at(txtString, tempPos) != " "){
- while(string_char_at(txtString, tempPos) != " ") {
- tempPos++;
- }
- txtString = string_insert("\n", txtString, tempPos);
- }
- else {
- txtString = string_insert("\n", txtString, tempPos);
- }
- }
- parsed = true;
- }
- txtHeight = string_height(txtCurrent);
- if (txtLetters >= txtLength) && (keyboard_check_pressed(vk_anykey)) {
- instance_destroy();
- //with(oCamera) follow = oPlayer
- //Code above is to reset camera following assuming we want the camera t focus on the text
- }
- //Draw Event
- /// @description Insert description here
- // You can write your code in this editor
- var halfWidth = txtWidth *0.5;
- draw_set_colour(c_white);
- //draw_set_alpha(0.5);
- draw_roundrect_ext(x-halfWidth-txtBorder, y-txtHeight-(txtBorder*2), x+halfWidth+txtBorder, y, 20, 20, false);
- //draw a ittle arrow sprite from owner of the text (sign or character etc...)
- //draw_set_alpha(1);
- //Set the text parameters
- draw_set_text(c_black, fntXolonium, fa_center, fa_top);
- draw_text(x, y -txtHeight-txtBorder, txtCurrent);
- draw_set_colour(c_white);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement