B
basement ape
Guest
Hey all,
To get around a problem with alpha-blending on interpolated sprites I am creating new, dynamic sprite objects from within another object.
Like this:
(Create event):
(Draw event):
These objects are used to draw all kinds of level graphics; floor tiles, backgrounds etc. This here is for a big tree with the pointer 'dyn_spr_forest_bigtree1_bg1_CRT' for the dynamically created sprite.
The problem with this code is that every single instance will create a new dynamic sprite in their Create event, which will waste a lot of memory.
I'd like for the first instance to create a dynamic sprite within the Create event, and then for any other instances created after it to reference the first one's sprite instead of creating their own.
I'm not sure how to go about that tho. I tried doing 'if !instance_exists(obj_forest_bigtree1.dyn_spr_forest_bigtree1_bg1_CRT) { // create new sprite }' without any luck.
Anyone able to help me out?
To get around a problem with alpha-blending on interpolated sprites I am creating new, dynamic sprite objects from within another object.
Like this:
(Create event):
Code:
global.layer_BG = layer_create(objDepth, "Instances");
layer_add_instance(global.layer_BG, self);
bck_X = x;
bck_Y = y;
// for CRT mode we need to create a new sprite from a fully opaque sprite and a separate alpha channel sprite.
// The reason being that GMS2 will blend transparent regions to black on upscaling filtered sprites, leaving
// them with visible black outlines if we just draw them as normal.
var dynsurf = surface_create(316, 324);
surface_set_target(dynsurf);
draw_sprite(spr_forest_bigtree1_bg1_CRT, 0, 0, 0);
gpu_set_blendmode(bm_subtract);
draw_sprite(spr_forest_bigtree1_bg1_alpha, 0, 0, 0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
dyn_spr_forest_bigtree1_bg1_CRT = sprite_create_from_surface(dynsurf, 0, 0, 316, 324, false, true, 0, 0);
surface_free(dynsurf);
Code:
if global.CRT_Mode == false
{ draw_sprite_ext(spr_forest_bigtree1_bg1, 0, bck_X, bck_Y, 1, 1, 0, c_white, 1); }
else if global.CRT_Mode == true
{ draw_sprite_ext(dyn_spr_forest_bigtree1_bg1_CRT, 0, bck_X, bck_Y, 0.5, 0.5, 0, c_white, 1); }
The problem with this code is that every single instance will create a new dynamic sprite in their Create event, which will waste a lot of memory.
I'd like for the first instance to create a dynamic sprite within the Create event, and then for any other instances created after it to reference the first one's sprite instead of creating their own.
I'm not sure how to go about that tho. I tried doing 'if !instance_exists(obj_forest_bigtree1.dyn_spr_forest_bigtree1_bg1_CRT) { // create new sprite }' without any luck.
Anyone able to help me out?