Daniel Mallett
Member
I have the following code under the draw event of an object. This creates a surface then pops some bits inside it. This code works fine. My problem is I want to draw things inside the surface from another object. I assumed I could prefix obj_differentobject. followed by the surface name. However when I try to do this I get an error saying the surface does not exist. In summary my question is how to draw to a surface that was created with a different object from the one using the surface. Thanks in advance.
if(!surface_exists(grid_surface)) // Ensures that grid does not already exist (Prevents multiple instances)
{
grid_surface = surface_create(grid_surface_width, grid_surface_height); // Create grid surface
}
surface_resize(grid_surface, grid_surface_width, grid_surface_height); // Update surface parameters
surface_set_target(grid_surface); // Set grid surface target
draw_clear_alpha(grid_surface_colour, 1); // Clear grid surface
// DRAW CODE GOES HERE
surface_reset_target(); // Reset grid surface
draw_surface(grid_surface, grid_surface_x_offset, grid_surface_y_offset); // Draw grid surface
if(!surface_exists(grid_surface)) // Ensures that grid does not already exist (Prevents multiple instances)
{
grid_surface = surface_create(grid_surface_width, grid_surface_height); // Create grid surface
}
surface_resize(grid_surface, grid_surface_width, grid_surface_height); // Update surface parameters
surface_set_target(grid_surface); // Set grid surface target
draw_clear_alpha(grid_surface_colour, 1); // Clear grid surface
// DRAW CODE GOES HERE
surface_reset_target(); // Reset grid surface
draw_surface(grid_surface, grid_surface_x_offset, grid_surface_y_offset); // Draw grid surface