I have been wanting to get back into some #gamedev tutorials for quite some time now. For the time being, I’m going to start doing weekly Game Maker: Studio tutorials to get things rolling. I have a fairly long list of requests, but feel free to send your other ideas my way!
What are blend modes? Blend modes tell GM what formula(s) to use when blending pixels (your source) with pixels that have previously been drawn to the screen (your destination). By default, GM uses a mode called bm_normal. This mode draws everything how you’d typically expect things to be drawn. If you have a red pixel, and you draw blue over the top of it, it becomes a blue pixel (this is somewhat dependent on the alpha channel of each pixel, as well).
Extended Blend Modes
Ok, so what are extended blend modes? Extended blend modes are a bit more difficult to grasp for most beginner to intermediate users. When setting an extended blend mode, you choose a mode for both your source and destination, separately.
The formula for drawing a pixel to the screen is as follows:
((Rs, Gs, Bs, As) * BLEND_MODE_INFO_SOURCE) + ((Rd, Gd, Bd, Ad) * BLEND_MODE_DEST)
Today I will talk about an applicable example that I use in both my previous project, INK, and my current project, FaraWay. This extended blend mode combines both bm_dest_alpha (Ad, Ad, Ad, Ad) and bm_inv_src_alpha (1-As, 1-As, 1-As, 1-As). If you can’t tell by looking at it, this blend mode draws pixels ONLY to positions that are currently drawn to already.
This is how I get ink to splatter correctly on non-rectangular objects (like spikes) in INK. Simply put, it prevents anything from “drawing outside of the lines”.
I also use this effect to draw silhouettes in our new Spaceboy Games project, FaraWay. When an object is behind another object, you draw the *behind* object blended with black (after applying the blend mode) to draw all or partial silhouettes on top of the *front* object.
I have attached a sample project that allows you to mess with this blend mode by drawing colorful shapes when the left mouse button is down. The extended blend mode allows you to scribble around freely without any of the ink effecting anything other than the blank white sprite space (the black background is left unaltered).
I hope this inspires you to come up with cool new effects for your games!