Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- By Oliver @pixelchipcode
- This code creates a dynamic, colorful trailing text effect that follows the mouse pointer in GameMaker. The main text stays in the center of the mouse position, and the trailing shadows follow behind with a shrinking and color-cycling effect.
- Features:
- - Shadow trail effect: Each instance of the text follows the mouse, progressively shrinking and cycling through a rainbow of colors.
- - Custom line height: Allows control over the spacing between lines of text for a multi-line setup.
- - Smooth movement: The trail follows smoothly behind the mouse, interpolating positions using a lerp function to ensure fluid motion.
- - Blending modes: The trail uses additive blending (bm_add) for vibrant color effects, while the main text is drawn using normal blending.
- Main Components:
- - **shadow_colors**: An array defining the colors that cycle through the text trail.
- - **text**: The text to be displayed, including line breaks using '\n'.
- - **mouse_trail**: An array that stores the previous positions of the mouse to create the trailing effect.
- - **shrink_speed**: Controls how quickly the trailing text shrinks as it moves further back in the trail.
- - **line_height**: Allows control over the spacing between lines in multi-line text.
- How it works:
- 1. The mouse's current position is tracked and stored in the `mouse_trail` array, which keeps a history of past positions.
- 2. The text trail is drawn at each past mouse position, shrinking progressively and cycling through the defined colors.
- 3. The main text is drawn at the current mouse position on top of the trail.
- Customize:
- - Modify `trail_length` to adjust the number of trailing instances.
- - Adjust `shrink_speed` to control how quickly the trailing text shrinks.
- - Change `line_height` to fine-tune the spacing between lines of text.
- */
- //create
- // Initialize the shadow colors in the Create event
- shadow_colors = [
- c_red,
- c_orange,
- c_yellow,
- c_lime,
- c_aqua,
- c_blue,
- c_purple
- ];
- // Set the font
- draw_set_font(Font1);
- draw_set_halign(fa_center)
- // Define the text
- text = "Nothing\nis real";
- // Time variable for animation
- time_offset = 0;
- // Control the speed and distance of the effect
- shrink_speed = 0.96; // Controls how much each text shrinks (closer to 1 = slower shrink)
- distance_offset = 8; // Controls the distance between layers
- // Mouse trail positions, store past mouse positions
- trail_length = 10; // Number of past positions to store (length of the tail)
- mouse_trail = []; // Initialize an empty array to store positions
- // Initialize all positions to the current mouse position to start aligned
- for (var i = 0; i < trail_length; i++) {
- array_push(mouse_trail, [mouse_x, mouse_y]);
- }
- // Store the last position of the mouse for checking movement
- last_mouse_x = mouse_x;
- last_mouse_y = mouse_y;
- //step
- // Add the current mouse position to the trail but keep positions smooth
- for (var i = trail_length - 1; i > 0; i--) {
- // Smooth transition of each position towards the one in front of it
- mouse_trail[i][0] = lerp(mouse_trail[i][0], mouse_trail[i - 1][0], 0.2);
- mouse_trail[i][1] = lerp(mouse_trail[i][1], mouse_trail[i - 1][1], 0.2);
- }
- // Set the first trail position to the current mouse position
- mouse_trail[0][0] = mouse_x;
- mouse_trail[0][1] = mouse_y;
- // Increment the time_offset to animate the snake-like effect (for color cycling)
- time_offset += 0.05;
- //draw
- gpu_set_blendmode(bm_add);
- // Define the custom line height for the text
- line_height = 110; // Adjust as needed
- // Loop through the trail and draw text at each past position
- for (var i = 0; i < trail_length; i++) {
- // Get the current color index but reverse the cycling so colors flow away from the main font
- var color_index = (trail_length - i + time_offset * 10) mod array_length(shadow_colors);
- // Set the current color
- draw_set_color(shadow_colors[color_index]);
- // Calculate scale for shrinking effect
- var scale = power(shrink_speed, i); // Shrinks progressively
- // Get the position from the trail
- var x_pos = mouse_trail[i][0];
- var y_pos = mouse_trail[i][1];
- // Split the text into lines using \n as the delimiter
- var lines = string_split(text, "\n");
- // Loop through each line and draw it with custom line spacing
- for (var j = 0; j < array_length(lines); j++) {
- draw_text_transformed(
- x_pos,
- y_pos + (j * line_height), // Adjust Y position for each line
- lines[j], // Draw each line separately
- scale,
- scale,
- j // No rotation needed
- );
- }
- }
- // Draw the main text on top (default color, purple as per your example)
- gpu_set_blendmode(bm_normal);
- draw_set_color(c_white);
- // Split the main text into lines for the final drawing
- var lines = string_split(text, "\n");
- // Loop through the lines and draw them with custom spacing
- for (var j = 0; j < array_length(lines); j++) {
- draw_text(mouse_x, mouse_y + (j * line_height), lines[j]);
- }
Advertisement
Add Comment
Please, Sign In to add comment