PixelChipCode

Breathing text effect in Gamemaker

Oct 23rd, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.67 KB | Source Code | 0 0
  1. //Breathing text effect in GameMaker by oliver @pixelchipcode
  2. //Create
  3. text_lines = [
  4.     "Breathing Text Line 1",
  5.     "Breathing Text Line 2",
  6.     "Breathing Text Line 3",
  7.     "Breathing Text Line 4",
  8.     "Breathing Text Line 5"
  9. ]; // An array holding each line of text
  10.  
  11. base_spacing = 8;      // Base spacing between letters
  12. amplitude = 10;        // How much the spacing varies (breathe out)
  13. breathing_speed = 0.009; // Speed of breathing
  14. time = 0;              // Keeps track of time
  15. line_height = 12;      // Vertical space between each line of text
  16. offset_per_line = 0.1; // Offset
  17.  
  18. //step
  19. time += breathing_speed;
  20.  
  21. //draw
  22. var start_x = 10; // Starting X position for drawing text
  23. var start_y = 10; // Starting Y position for the first line of text
  24.  
  25. for (var line = 0; line < array_length(text_lines); line++) {
  26.     var current_x = start_x;
  27.     var current_y = start_y + (line * line_height); // Calculate Y position based on line number
  28.    
  29.     // Apply a breathing offset for each line to create the wave effect
  30.     var line_time = time + (line * offset_per_line);
  31.     var spacing_offset = (1 + cos(line_time)) * 0.5 * amplitude;
  32.    
  33.     // Get the current line of text
  34.     var text = text_lines[line];
  35.    
  36.     // Loop through each character in the current line
  37.     for (var i = 0; i < string_length(text); i++) {
  38.         var char = string_char_at(text, i+1); // Get each character one by one
  39.        
  40.         // Draw the character at the current position
  41.         draw_text(current_x, current_y, char);
  42.        
  43.         // Update X position for the next character with breathing effect
  44.         current_x += base_spacing + spacing_offset;
  45.     }
  46. }
  47.  
Tags: gameMaker
Advertisement
Add Comment
Please, Sign In to add comment