GameCrom Engine Commands

This page contains the most important functions available for scripts inside the GameCrom engine.

💡 Tip: all functions can be used directly in scripts without importing anything. They run inside the engine environment with full access to objects, components and physics.

🚀 Object Management

FunctionDescription
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.

🎮 Input and Controls

FunctionDescription
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:
  • Keyboard: "a", "w", "ArrowUp", "Enter", " "
  • Gamepad: "gamepad_a", "gamepad_right", "gamepad_l1"…
  • Multitouch: "touch0", "touch1", "touch2"…
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().
_onClickDownEvent triggered when the user presses the button (mouse or touch).
_onClickUpEvent triggered when the user releases the button and the click is confirmed.
mouse.x / mouse.yCurrent cursor position inside the canvas.
mouse.down / mouse.upIndicates if the main mouse button is pressed or released.

💡 Animation and Components

FunctionDescription
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:
  • The object reference
  • The name of the particle system object
Examples:
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");

🧱 Physics and Movement

FunctionDescription
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.

🧮 Math and Utilities

FunctionDescription
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:
  • Mouse clicks
  • Touch input
  • Object selection
Example:
const pos = ScreenToWorld(mouse.x, mouse.y);
console.log(pos.x, pos.y);
WorldToScreen(x, y) Converts world coordinates into screen coordinates, applying the current camera offset.

Very useful for:
  • HUD elements attached to objects
  • Floating texts
  • Visual indicators
Example:
const pos = WorldToScreen(player.x, player.y);
drawText("Player", pos.x, pos.y - 20);
GetWorldPosition(obj) Returns the actual world position of an object, taking its hierarchy into account.

Behavior:
  • If the object has a parent → adds localX / localY to the parent's position
  • If the object has no parent → returns x / y directly
Ideal for:
  • Shooting points
  • Hardpoints
  • Precise spawns
Example:
const gun = getChildByName(ship, "SALIDA_DISPARO");
const pos = GetWorldPosition(gun);
spawnBullet(pos.x, pos.y);

🎨 Render and GUI

FunctionDescription
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.

🕹️ Scenes and Game

FunctionDescription
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.

⏱️ Timers

FunctionDescription
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.