• 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!

Clipping masks functionality

P

PWL

Guest
Hey all! Here goes my first post on the new GMC!

I need to be able to change the pattern of my character and it would make life so much easier if I could just draw the pattern within the white portion of my sprite instead of creating all sprites with all the patterns.



Is there some blend mode I can use that lets me get this result? I want the green pattern to appear within the white of my character.
 

FrostyCat

Redemption Seeker
In your case, the correct blend mode is (bm_dest_alpha, bm_inv_src_alpha).
  • You want the overlaying image to take on the transparency of the original image. That's bm_dest_alpha for source.
  • You want the original image to influence colour only where the overlay is transparent. That's bm_inv_src_alpha for destination.
This requires a surface the same size as the sprite, so that the alpha can be managed independent of the background.

Create:
Code:
s = surface_create(sprite_width, sprite_height);
Draw:
Code:
if (!surface_exists(s)) {
  s = surface_create(sprite_width, sprite_height);
}
surface_set_target(s);
draw_set_blend_mode(bm_normal);
draw_sprite(sprite_index, image_index, sprite_xoffset, sprite_yoffset);
draw_set_blend_mode_ext(bm_dest_alpha, bm_inv_src_alpha);
draw_sprite(spr_overlay, 0, 0, 0);
draw_set_blend_mode(bm_normal);
surface_reset_target();
draw_surface(s, x-sprite_xoffset, y-sprite_yoffset);
While visual aids are helpful in some cases, in the long term that is no replacement for a grasp of fundamentals. Go into the Manual and read the table of blend mode constants. The next time you have issues like this, come up with a mathematical colour model and match it to the constants.
 
P

PWL

Guest
Thank you both. I find the blend modes to be quite confusing, so it's nice to have an example to work with when trying to understand it.

The snippet worked perfect with a few modifications, like bm_dest_colour instead so it only draws on the white :)
 
Top