This way is correct:
Code:
// in create event:
surf = surface_create(w,h);
// in draw event:
if(surface_exists(surf){ // <-- be sure you check this first
surface_set_target(surf);
draw_sprite() // you update the surface
surface_reset_target();
draw_surface() // you draw the [updated] surface to the screen
}
This other way will NOT work:
Code:
// in create event:
surf = surface_create(w,h);
// in draw event:
if(surface_exists(surf)){ // <-- be sure you check this first
draw_surface() // you draw the [not yet updated] surface to the screen
surface_set_target(surf);
draw_sprite() // you update the surface
surface_reset_target();
}
The reason is because the latter is not being done in the correct order. Analogy: The first way (the correct way) is like if I write an essay and print it out and give it to my teacher. My teacher will then be able to read my essay. The second way (the incorrect way) is like if I were to open a new document, print out a blank page, give the blank page to my teacher, and then write my essay afterwards. No matter what I write afterwards, the teacher isn't going to see any of it, because the only thing I've turned in is a blank page.
As for your primary question, that depends on what you're trying to make it do. If you just want to draw a sprite to the surface, then yes, it would work. But if you want to draw a sprite to the surface
and see it on the screen, then no, it would not work, because you never drew the surface to the screen.
Another thing to keep in mind is, the screen is automatically cleared every step, but surfaces are not automatically cleared every step. It's also a good idea to clear the surface (using draw_clear or draw_clear_alpha) before drawing anything to it.