new RealTypeBox()
Editable text field that looks like part of the canvas but relies on a hidden HTML <input> for actual typing, giving you proper IME / copy-paste support.
Editable text field that looks like part of the canvas but relies on a hidden HTML <input> for actual typing, giving you proper IME / copy-paste support.
const chat = createTypeBox(100, 600, 500, 40);
chat.onSubmit(t => console.log("player typed:", t));
- Source:
Extends
Members
focused :boolean
Whether the box currently has focus.
Whether the box currently has focus.
Type:
- boolean
- Source:
h :number
Height of the visible field.
Height of the visible field.
Type:
- number
- Source:
hidden :boolean
Whether the object is hidden
.Whether the object is hidden
Type:
- boolean
- Inherited From:
- Source:
input :HTMLInputElement
Type:
- HTMLInputElement
- Source:
r :number
Corner radius for the rounded rect.
Corner radius for the rounded rect.
Type:
- number
- Source:
submitCbs :Array
Submit callbacks.
Submit callbacks.
Type:
- Array
- Source:
value :string
Current text value.
Current text value.
Type:
- string
- Source:
w :number
Width of the visible field.
Width of the visible field.
Type:
- number
- Source:
x :number
X position
.X position
Type:
- number
- Overrides:
- Source:
y :number
Y position
.Y position
Type:
- number
- Overrides:
- Source:
Methods
_hit(mx, my) → {boolean}
Hit-test helper for click handling.
Hit-test helper for click handling.
Parameters:
| Name | Type | Description |
|---|---|---|
mx |
number | Mouse x (canvas coords). |
my |
number | Mouse y (canvas coords). |
- Source:
Returns:
True if the point is inside the box.
- Type
- boolean
blur()
Removes keyboard focus from this textbox.
Removes keyboard focus from this textbox.
- Source:
delete()
Completely removes the textbox and its DOM element.
Completely removes the textbox and its DOM element.
(Called automatically if you use your engine’s delete().)
- Source:
draw()
Draws the box and positions its DOM <input> each frame.
Draws the box and positions its DOM <input> each frame. Called automatically by the engine’s main loop.
- Overrides:
- Source:
focus()
Gives keyboard focus to this textbox.
Gives keyboard focus to this textbox.
- Source:
goTo(x, y)
Sets the sprite’s position.
Sets the sprite’s position.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | The new x-coordinate. |
y |
number | The new y-coordinate. |
- Source:
onSubmit(cb)
Register a callback that runs when the user presses Enter.
Register a callback that runs when the user presses Enter.
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
string | Handler receiving submitted text. |
- Source: