PixelChipCode

Quick and dirty slow mo effect Gamemaker

Nov 27th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.99 KB | Source Code | 0 0
  1. // oliver @pixelchipcode
  2. //create
  3. // Default frame rate settings
  4. default_fps = 60;
  5. target_fps = default_fps;
  6. change_speed = 1; // Speed of transition (higher = faster change)
  7. current_fps = default_fps;
  8.  
  9. // Set the initial game speed
  10. game_set_speed(default_fps, gamespeed_fps);
  11.  
  12. //step
  13. if (mouse_check_button(mb_left)) {
  14.     // Set the slow-motion target frame rate on mouse press
  15.     target_fps = 10; // Example: Slow motion at 30 FPS
  16. } else {
  17.     // Reset to the normal frame rate on release
  18.     target_fps = default_fps;
  19. }
  20.  
  21. // Smoothly interpolate the current FPS towards the target FPS
  22. if (abs(current_fps - target_fps) > 0.1) { // Only adjust if there's a noticeable difference
  23.     current_fps = lerp(current_fps, target_fps, change_speed * delta_time / 100000);
  24.    
  25.     // Clamp and round the FPS to ensure valid values
  26.     current_fps = clamp(round(current_fps), 1, 1000); // FPS range: 1 to 1000
  27.  
  28.     // Set the game speed
  29.     game_set_speed(current_fps, gamespeed_fps);
  30. }
  31.  
Tags: gameMaker
Advertisement
Add Comment
Please, Sign In to add comment