Newb question: How to draw onto a surface?

Adry

Member
Hi! I'm trying to understand surfaces, not the application_surface, but rather an individual surface that I can manipulate..
This is probably a beginner question, but, as the title suggests, how do I draw onto a surface? More specifically,
how do I draw my Layer background sprite onto its own surface? Would appreciate any and all guidance!

Thanks,

GML:
layer_background_sprite(back_id, BG_Random);
P.S. I'm researching and trying to learn about it myself as I write,
just wanted to pose the question if any of ya'll had any pertinent insight :)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You don't need the layer functions for this. Simply set the surface, draw the actual sprite, then reste the surface... so...
GML:
// IN THE CREATE EVENT
surface = -1; // Initialise the variable that wil hold the surface ID

// IN THE DRAW EVENT
if !surface_exists(surface) // Check and see if surface exists
{
// Surface doesn't exist so create it and make it the size of the background sprite
surface = surface_create(sprite_get_width(BG_Random), sprite_get_height(BG_Random));
// Now draw the background to the surface
surface_set_target(surface);
draw_sprite(BG_Random, 0, 0, 0);
surface_reset_target();
}
else
{
// Draw the surface
draw_surface(surface, 0,  0);
}
 

Adry

Member
You don't need the layer functions for this. Simply set the surface, draw the actual sprite, then reste the surface... so...
GML:
// IN THE CREATE EVENT
surface = -1; // Initialise the variable that wil hold the surface ID

// IN THE DRAW EVENT
if !surface_exists(surface) // Check and see if surface exists
{
// Surface doesn't exist so create it and make it the size of the background sprite
surface = surface_create(sprite_get_width(BG_Random), sprite_get_height(BG_Random));
// Now draw the background to the surface
surface_set_target(surface);
draw_sprite(BG_Random, 0, 0, 0);
surface_reset_target();
}
else
{
// Draw the surface
draw_surface(surface, 0,  0);
}
Awesome! thank you so much Nocturne! That helps tremendously,
seeing things visually and in the order of events as you laid it out makes me understand the process a bit better.
Will be working with this code and implementing it soon!
 
Top