Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Breathing text effect in GameMaker by oliver @pixelchipcode
- //Create
- text_lines = [
- "Breathing Text Line 1",
- "Breathing Text Line 2",
- "Breathing Text Line 3",
- "Breathing Text Line 4",
- "Breathing Text Line 5"
- ]; // An array holding each line of text
- base_spacing = 8; // Base spacing between letters
- amplitude = 10; // How much the spacing varies (breathe out)
- breathing_speed = 0.009; // Speed of breathing
- time = 0; // Keeps track of time
- line_height = 12; // Vertical space between each line of text
- offset_per_line = 0.1; // Offset
- //step
- time += breathing_speed;
- //draw
- var start_x = 10; // Starting X position for drawing text
- var start_y = 10; // Starting Y position for the first line of text
- for (var line = 0; line < array_length(text_lines); line++) {
- var current_x = start_x;
- var current_y = start_y + (line * line_height); // Calculate Y position based on line number
- // Apply a breathing offset for each line to create the wave effect
- var line_time = time + (line * offset_per_line);
- var spacing_offset = (1 + cos(line_time)) * 0.5 * amplitude;
- // Get the current line of text
- var text = text_lines[line];
- // Loop through each character in the current line
- for (var i = 0; i < string_length(text); i++) {
- var char = string_char_at(text, i+1); // Get each character one by one
- // Draw the character at the current position
- draw_text(current_x, current_y, char);
- // Update X position for the next character with breathing effect
- current_x += base_spacing + spacing_offset;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment