• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Newb question: How to draw onto a surface?

A

Adry

Guest
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);
}
 
A

Adry

Guest
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