Question: How do you use colors in GameMaker?
Answer
In GameMaker, colors can be used to enhance the visual aesthetics of games. You can set the color of sprites, backgrounds, fonts, and other elements.
-
Setting Colors for Drawing: When drawing shapes, text, or sprites, you can set the drawing color using the
draw_set_color(color)
function. Thecolor
argument is typically defined using GameMaker's built-in color constants (likec_red
,c_green
, etc.), or with custom colors created using themake_color_rgb(red, green, blue)
function.draw_set_color(c_red); // Set the drawing color to red draw_rectangle(x1, y1, x2, y2, false); // Draw a red rectangle
-
Creating Custom Colors: You can create your own colors by specifying the red, green, and blue components with values between 0 and 255.
var myColor = make_color_rgb(128, 64, 255); // Create a custom purple color draw_set_color(myColor); draw_circle(x, y, radius, false); // Draw a circle with the custom color
-
Changing the Blend Mode: Blending modes determine how colors mix when drawn on top of each other. You can change blend modes using
gpu_set_blendmode(bm_mode)
.gpu_set_blendmode(bm_add); // Set the blend mode to additive blending draw_sprite(spr_Example, 0, x, y); // Draw a sprite with additive blending gpu_set_blendmode(bm_normal); // Reset to normal blending mode
-
Using Color with Fonts: When drawing text, you can also use
draw_set_color()
to define the text color before callingdraw_text()
.draw_set_color(c_blue); // Set the text color to blue draw_text(x, y, "Hello World!"); // Draw blue text at position (x, y)
-
Alpha Transparency: In addition to RGB (red, green, blue), you can also specify alpha transparency when creating a color using
make_color_rgba()
. Alpha values range from 0 (completely transparent) to 255 (completely opaque).var myTransparentColor = make_color_rgba(255, 255, 255, 128); // Create a semi-transparent white color draw_set_color(myTransparentColor); draw_rectangle(x1, y1, x2, y2, true); // Draw a semi-transparent rectangle
-
Gradient Effects: GameMaker also allows you to draw gradients by specifying different colors for different points.
draw_gradient_horiz(x1, y1, x2, y2, c_red, c_blue); // Horizontal gradient from red to blue
Remember that the exact representation of colors may vary depending on the display settings and hardware.
Was this content helpful?
Other Common Game Engines Questions (and Answers)
- Can You Use C# in Unreal Engine?
- Is Unreal Engine Open Source?
- Can Unreal Engine make 2D games?
- Does Unreal Engine Use Python?
- What Language Does Unreal Engine Use?
- Does Unreal Engine Use JavaScript?
- Does Unreal Engine work on Linux?
- How Do I Uninstall Unreal Engine 5?
- Is Blender or Unreal Engine Better?
- Does Unreal Engine Work on Mac?
- Why Is Unreal Engine So Laggy?
- Can I Run Unreal Engine 5 Without a Graphics Card?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost