I am using GM8 and trying to create the wave distortion effect but on the background only. To do this, you have to use the surface_create command.
The problem is that it draws the entire screen, no matter what depth I have the distortion object on. What I'm trying to do is only have it so that the level background has the distortion wavy effect only and not the foreground and other objects. I am attempting to create an effect of heat on the background. I simply thought setting the depth of the distortion object to be drawn behind the objects and foreground would work, but I'm guessing the surface_create function captures everything on screen to where everything is waving in distortion. I'm just trying to get the background only to have the effect. Do I need to create a different view for this or is there a totally easy way that I'm missing? I'll post the code I'm using here if needed to clarify more.
Background Distortion
Started by MalcomX, Jul 21 2011 12:50 AM
5 replies to this topic
#1
Posted 21 July 2011 - 12:50 AM
#2
Posted 21 July 2011 - 06:23 AM
The surface_create function does not draw anything onto the surface. How are you drawing to it?
Is your background just one image, or is there a tileset or group of objects that also need to be included?
Is your background just one image, or is there a tileset or group of objects that also need to be included?
#3
Posted 21 July 2011 - 07:48 PM
I'll post the code I'm using:
CREATE:
END STEP EVENT:
DRAW:
With this code, EVERYTHING on screen has the distortion effect. I just want the BACKGROUND to have the effect. Is there any way to edit this code to make that work?
CREATE:
global.capture = false; // This flag is used to check if we're
// capturing the screen.
screen_surface = surface_create(256, 256); // This is the surface that will
// hold the screen data.
/* These are the variables wich control the actual distortion wave */
angle_x = 0;
angle_y = 0;
current_angle_x = 0;
current_angle_y = 0;
angle_increment_x = degtorad(0.3);
angle_increment_y = degtorad(0.3);
wave_pitch_x = degtorad(1.4);
wave_offset_x = 12;
wave_pitch_y = degtorad(0.1);
wave_offset_y = 8;
scaled = (320+(wave_offset_x*8))/320;
steps = 4;
start_y = 0;
END STEP EVENT:
// Check if we lost the surface
if (!surface_exists(screen_surface)){ surface_create(256, 256);}
// Capture the screen
surface_set_target(screen_surface);
global.capture = true;
draw_clear_alpha(c_black, 0); // Clear surface
screen_redraw(); // Call all redraw events
global.capture = false;
surface_reset_target(); // End with screen capture
current_angle_x += angle_increment_x;
current_angle_y += angle_increment_y;
DRAW:
var wave_x, texture_y, texture_step;
draw_background_tiled(bkgMMZ, view_xview*0.97, view_yview*0.95);
if (global.capture == false)
{
// Draw the screen as a distorted surface
texture_step = 1/view_hview;
angle_x = (current_angle_x) + wave_pitch_x*start_y;
texture_y = texture_step * start_y;
draw_primitive_begin_texture(pr_trianglestrip, surface_get_texture(screen_surface));
for (y=start_y; y<=(view_hview+steps); y+=steps)
{
wave_x = view_xview + sin(angle_x)*wave_offset_x-wave_offset_x;
draw_vertex_texture_color(wave_x,view_yview+y, 0, texture_y, c_white, 1);
draw_vertex_texture_color(view_xview+view_wview+(wave_offset_x), view_yview+y, 1, texture_y, c_white, 1);
angle_x += wave_pitch_x*steps;
angle_y += wave_pitch_y*steps;
texture_y += texture_step*steps;
}
draw_primitive_end();
}
With this code, EVERYTHING on screen has the distortion effect. I just want the BACKGROUND to have the effect. Is there any way to edit this code to make that work?
Edited by MalcomX, 21 July 2011 - 07:50 PM.
#4
Posted 21 July 2011 - 08:36 PM
What you've done is create the surface, set the drawing target to your surface, then called screen_redraw(). That function causes all objects/etc to be redrawn. Because the drawing target is your surface, everything is being redrawn on your surface. You need to only draw the things you want drawn.
#5
Posted 21 July 2011 - 08:58 PM
So you're saying all I need to do is replace the screen_redraw function to only redraw the background? Or to not create the surface altogether?
#6
Posted 21 July 2011 - 11:43 PM
If it's just the background you want to be distorted, then just draw the background onto the surface. Don't use screen_redraw().
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











