Last active
April 19, 2019 23:28
-
-
Save yuigoto/41e40b2ea7f76bc7e42a5a3cac21b2a8 to your computer and use it in GitHub Desktop.
[GameMaker : Gerenciando Surfaces] Exemplo de como gerenciar surfaces em GML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @description Inicializa parâmetros do objeto | |
// Inicializa a surface como noone | |
surface = noone; | |
// Prefiro ter a variável inicializada no create, por segurança, | |
// na hora de checar depois |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @description Verifica se surface existe e destroi no Room End ou Destroy Event | |
if (surface_exists(surface)) surface_free(surface); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @description Verifica se a surface existe e desenha/cria | |
// A surface existe e foi inicializada? | |
if (surface_exists(surface)) { | |
// Define target, limpa, etc. | |
surface_set_target(surface); | |
draw_clear_alpha(c_white, 0); | |
// Execute o que você quer desenhar na surface... | |
// ... | |
// Reseta o target pra application_surface | |
surface_reset_target(); | |
} else { | |
// Se a surface não existe, cria uma nova | |
// Utilize as dimensões que desejar, ok? :) | |
surface = surface_create(640, 480); | |
// Quando crio a surface, eu gosto de limpar ela primeiro | |
// Mas isso fica a seu criterio | |
surface_set_target(surface); | |
draw_clear_alpha(c_white, 0); | |
surface_reset_target(); | |
} | |
// E, normalmente, apenas desenho a surface se ela for != noone | |
if (surface != noone) { | |
draw_surface(surface, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment