Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. //Create Event
  2. /// @description Insert description here
  3. // You can write your code in this editor
  4.  
  5. //Speed at which text is drawn to the screen every frame
  6. txtSpeed = 1;
  7.  
  8. //How many letters to draw
  9. txtLetters = 0;
  10.  
  11. //The whole string we actually want to draw
  12. 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!";
  13.  
  14. //Get the length of the string
  15. txtLength = string_length(txtString);
  16.  
  17. //Equal to some of the text
  18. txtCurrent = "";
  19.  
  20. //Declare some Variable
  21. txtWidth = 0;
  22. txtMaxWidth = 200;
  23. txtHeight= 0;
  24. txtBorder = 10;
  25.  
  26. charNum = 0;
  27.  
  28. parsed = false;
  29.  
  30.  
  31. //Step Event
  32. /// @description Insert description here
  33. // You can write your code in this editor
  34.  
  35. txtLetters += txtSpeed;
  36.  
  37. txtCurrent = string_copy(txtString, 1, floor(txtLetters));
  38.  
  39. draw_set_font(fntXolonium);
  40.  
  41. txtWidth = string_width(txtCurrent);
  42.  
  43. if ((txtWidth > txtMaxWidth) && (parsed == false)){
  44.  
  45. //This will give us the character position to insert a line break
  46. charNum = string_length(txtCurrent);
  47.  
  48. //Using the string length get the number of line breaks we need to add
  49. var numLineBreaks = string_length(txtString) div charNum;
  50. var lineBreakPosition = 0;
  51. var tempPos = 0;
  52.  
  53. for (var i = 1; i <= numLineBreaks; i++) {
  54. lineBreakPosition = charNum * i;
  55. tempPos = lineBreakPosition;
  56.  
  57. if (string_char_at(txtString, tempPos) != " "){
  58. while(string_char_at(txtString, tempPos) != " ") {
  59. tempPos++;
  60. }
  61. txtString = string_insert("\n", txtString, tempPos);
  62. }
  63. else {
  64. txtString = string_insert("\n", txtString, tempPos);
  65. }
  66. }
  67. parsed = true;
  68.  
  69. }
  70.  
  71. txtHeight = string_height(txtCurrent);
  72.  
  73. if (txtLetters >= txtLength) && (keyboard_check_pressed(vk_anykey)) {
  74. instance_destroy();
  75. //with(oCamera) follow = oPlayer
  76. //Code above is to reset camera following assuming we want the camera t focus on the text
  77. }
  78.  
  79. //Draw Event
  80. /// @description Insert description here
  81. // You can write your code in this editor
  82.  
  83. var halfWidth = txtWidth *0.5;
  84.  
  85. draw_set_colour(c_white);
  86. //draw_set_alpha(0.5);
  87.  
  88. draw_roundrect_ext(x-halfWidth-txtBorder, y-txtHeight-(txtBorder*2), x+halfWidth+txtBorder, y, 20, 20, false);
  89.  
  90. //draw a ittle arrow sprite from owner of the text (sign or character etc...)
  91. //draw_set_alpha(1);
  92.  
  93. //Set the text parameters
  94. draw_set_text(c_black, fntXolonium, fa_center, fa_top);
  95. draw_text(x, y -txtHeight-txtBorder, txtCurrent);
  96. draw_set_colour(c_white);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement