This page contains the most important functions available for scripts inside the GameCrom engine.
| Function | Description |
|---|---|
objects |
Variable that contains all the objects in the scene |
getObjectByName(name) | Returns the first object with that name. |
getObjectByTag(tag) | Finds an object by its assigned tag. |
getObjectsByType(type) | Returns all objects of a given type (e.g., "enemy"). |
destroyObject(obj) | Destroys an object in the scene. |
destroyObjectTime(obj, seconds) | Destroys an object after a given time. |
setParent(child, parent) | Assigns a parent to an object to maintain hierarchy. |
getParent(obj) | Returns the parent object, if any. |
getAllChildren(obj) | Returns all direct or recursive child objects. |
detachAllChildren(obj) | Detaches all children from the object. |
instantiateObject(config, scriptPath) | Creates a new object at runtime. |
instantiatePrefab(name, x, y) |
Instantiates a saved prefab and creates it in the scene with all components, properties and scripts. |
| Function | Description |
|---|---|
IsAnyPressed(...keys) | Returns true if any of the given keys are pressed. |
OnKeyDown(obj, key) |
Runs when a key, gamepad button or finger (touch) is pressed.
The key parameter can be:
|
OnKeyUp(obj, key) |
Runs when a key/button/touch is released. Works with keyboard, gamepad and multitouch. |
OnKeyHold(obj, key) |
Runs every frame while the key/button/touch remains pressed. Ideal for continuous movement, charging attacks, acceleration, etc. |
touch0, touch1, touch2... |
Multitouch identifiers. Each active finger becomes a “virtual key”.
touch0 = first finger touch1 = second finger touch2 = third finger Works with OnKeyDown / OnKeyUp / OnKeyHold and also with IsAnyPressed().
|
_onClickDown | Event triggered when the user presses the button (mouse or touch). |
_onClickUp | Event triggered when the user releases the button and the click is confirmed. |
mouse.x / mouse.y | Current cursor position inside the canvas. |
mouse.down / mouse.up | Indicates if the main mouse button is pressed or released. |
| Function | Description |
|---|---|
getComponent(obj, type) | Returns the first component of the given type. |
addComponent(obj, comp) | Adds a new component to the object. |
createAnimationController() | Creates an animation controller. |
PlayAnimation(obj, name) | Plays a specific animation on an object. |
createAudioSource(clip, volume, loop) | Creates a playable audio component. |
PlayAudioSource(obj) | Plays the object's AudioSource. |
StopAudioSource(obj) | Stops the object's AudioSource. |
FadeInAudio(obj, time) | Fades in from volume 0 to full volume. |
FadeOutAudio(obj, time) | Fades out progressively and stops the sound. |
PlaySound(file, volume) | Plays a standalone sound (One Shot). |
createPlatformMover(x, y, speed, loop) | Automatically moves platforms. |
createCameraController(follow, smooth) | Makes the camera follow a target. |
createParticleSystem() | Generates a basic particle system. |
PlayParticles(obj)PlayParticles("ObjectName") |
Immediately activates particle emission for the system,
even if playOnStart is set to false.You may pass:
PlayParticles(fxExplosion);PlayParticles("SmokeOutput");
|
StopParticles(obj)StopParticles("ObjectName") |
Stops emission of new particles, but keeps existing particles alive
until they fade out naturally. Examples: StopParticles(fxFire);StopParticles("Sparks");
|
| Function | Description |
|---|---|
AddForce(obj, x, y, force) | Applies a force to an object (Asteroids-style). |
Raycast(x1, y1, x2, y2, maxDist) | Casts a ray and detects collisions along its path. |
setPosition(obj, x, y) | Changes the object's world position. |
setRotation(obj, angle) | Sets an absolute rotation (in degrees). |
rotateObject(obj, delta) | Adds additional rotation to an object. |
Flip(obj, flipX, flipY) | Flips a sprite horizontally or vertically. |
DebugColliders() | Shows visual collider areas. |
| Function | Description |
|---|---|
lerp(a, b, t) | Linear interpolation between two values. |
lerpSmooth(a, b, speed, dt) | Smooth interpolation dependent on time. |
lerpPingPong(a, b, speed, timer) | Oscillation between two values. |
clamp(value, min, max) | Clamps a value within a range. |
randomRange(min, max) | Returns a random number between two values. |
Vector2(x, y) | 2D vector class with common operations. |
ScreenToWorld(x, y) |
Converts screen (canvas) coordinates into world coordinates,
taking the camera offset (offsetX, offsetY) into account.Useful for:
const pos = ScreenToWorld(mouse.x, mouse.y);
|
WorldToScreen(x, y) |
Converts world coordinates into screen coordinates,
applying the current camera offset. Very useful for:
const pos = WorldToScreen(player.x, player.y);
|
GetWorldPosition(obj) |
Returns the actual world position of an object,
taking its hierarchy into account. Behavior:
const gun = getChildByName(ship, "SALIDA_DISPARO");
|
| Function | Description |
|---|---|
setTexture(obj, fileName) |
Assigns a texture to the object using only the file name. Example: Sprite1.png |
getTexture(obj) |
Returns the file name of the current texture. |
drawText(text, x, y, options) | Draws styled text on the canvas. |
showToast(msg, type) | Displays a temporary floating message. |
DrawDebugLine(x1, y1, x2, y2) | Draws a debug line. |
DrawDebugCircle(x, y, r) | Draws a debug circle. |
RenderDebugDraw() | Renders all debug elements. |
DrawLine(x1, y1, x2, y2, color, width) |
Draws a permanent line in the world with rounded ends,
custom thickness and color. This function is NOT for debugging; it is used for real visual game effects, such as marking words in a word-search puzzle, paths, links, etc. ClearLines() removes all lines. Example: DrawLine(100, 120, 350, 420, "rgba(255,150,80,0.65)", 22);
|
ShowFPS() | Shows FPS. |
HideFPS() | Hides FPS. |
| Function | Description |
|---|---|
LoadSceneByName(name) | Loads a new scene by name. |
ReloadScene() | Reloads the current scene. |
GetSceneName() | Returns the current scene name. |
SavePlayerData(obj) | Saves player data in JSON format. |
LoadPlayerData() | Loads previously saved data. |
IsMobile() |
Returns true if the game is running on a mobile device or tablet (Android / iOS), and false when running on a desktop or laptop. |
| Function | Description |
|---|---|
Timer(seconds, function, loop, target) | Executes a function after a delay. |
updateTimers(dt) | Updates active timers. |
clearTimer(name) | Removes timers by name. |
pauseTimers(pause) | Pauses or resumes timers. |