🖋️ drawText(text, x, y, options)
📖 Description
Quickly draws text on screen with advanced styling options (color, font, alignment, outline, shadow, etc.)
and returns an object containing all information about the rendered text, including its size and
a hit-detection function (contains()).
🧠 Syntax
let info = drawText(text, x, y, options);
📥 Parameters
| Name |
Type |
Description |
Default |
text | string | Text to display. | — |
x | number | Horizontal screen position. | — |
y | number | Vertical screen position. | — |
options | object | Visual styling options (see table below). | {} |
🎨 options Object Properties
| Property | Type | Description | Default |
color | string | Text color. | "#fff" |
font | string | Font and size (e.g. "20px Arial"). | "20px Arial" |
align | string | Alignment ("left", "center", "right"). | "left" |
stroke | string | Text outline color. | null |
lineWidth | number | Outline thickness. | 2 |
shadowColor | string | Shadow color. | null |
shadowBlur | number | Shadow blur amount. | 0 |
shadowOffsetX | number | Horizontal shadow offset. | 2 |
shadowOffsetY | number | Vertical shadow offset. | 2 |
🔁 Return Value
Returns an object containing:
| Property | Type | Description |
text | string | The rendered text. |
x, y | number | Screen position. |
width, height | number | Automatically calculated text dimensions. |
color, font, align, stroke... | various | All applied style properties. |
contains(px, py) | function | Returns true if point (px, py) is inside the text area. |
✅ Basic Example
function LateUpdate(obj, dt) {
drawText("Hello GameCrom!", 250, 250);
}
🌈 Example with Styles & Detection
function LateUpdate(obj, dt) {
const info = drawText("LEVEL UP!", 250, 250, {
color: "#ff0",
font: "bold 36px 'Press Start 2P'",
align: "center",
stroke: "#000",
lineWidth: 4,
shadowColor: "rgba(0,0,0,0.6)",
shadowBlur: 8
});
// Detect if mouse is over the text
if (info.contains(mouseX, mouseY)) {
drawText("🖱️ Mouse Over!", 250, 290, { color: "#0f0", align: "center" });
}
}
🧠 Technical Details
- Should be used inside
LateUpdate() to be visible.
- Does not use project-loaded fonts.
- The
contains() area automatically adjusts based on alignment (left, center, right).
💡 Tip:
Use drawText() for HUDs, temporary messages, score displays or custom interfaces.
The returned object allows you to detect clicks, show tooltips or animate text easily.