🎮 GameObject Type

📖 Description

In GameCrom, a GameObject is the base type for every element in a scene: enemies, platforms, triggers, decorations or logic elements.

This type has no built-in behavior, making it the most flexible object in the engine. Its physical, visual and logical properties are fully controlled through scripts or components.

💡 Important:
GameObject is one of the possible values for the type field.
Every engine type (such as player, light, or particleSystem) extends these base properties.

⚙️ Base GameObject Properties

PropertyTypeDescriptionDefault
namestringName shown in the hierarchy."GameObject"
typestringObject type ("gameobject")."gameobject"
xnumberHorizontal position (pixels).0
ynumberVertical position.0
wnumberWidth of the object.32
hnumberHeight of the object.32
scaleXnumberHorizontal scale.1
scaleYnumberVertical scale.1
rotationnumberRotation in degrees.0
vxnumber Horizontal velocity (pixels/second). Commonly used as obj.x += obj.vx * dt. 0
vynumber Vertical velocity. Ideal for jumps or gravity: obj.vy += obj.gravity * dt. 0
gravitynumber Gravity intensity applied to the object.
If 0, the object will not fall.
You can adjust it to change the object's “weight”.
400
staticboolean If true, the object is static: it will not move nor be affected by physics or dynamic collisions. Ideal for walls, floors, or fixed platforms. false
colorstringRectangle color (if no sprite is assigned)."#ffffff"
opacitynumberTransparency (0–1).1
visiblebooleanDetermines if the object is drawn on screen.true
activebooleanIf inactive, it will not update.true
imagestringSprite path or name used for rendering.null
collisionbooleanEnables physics collisions (AABB or circle).false
triggerbooleanDetects enter/exit events only; no physical blocking.false
tagstringIdentification tag (e.g. “Player”, “Enemy”).""
layernumberDraw order (0–31).0
componentsarrayAttached components (animation, audio, particles...)[]
scriptstring|nullAssigned script (e.g. "player_platform.js").null

🏃 Movement Example with Gravity

// Basic physics script
function Update(obj, dt) {
  if (!obj.static) {
    obj.vy += obj.gravity * dt; // gravity
    obj.x += obj.vx * dt;
    obj.y += obj.vy * dt;
  }

  // Floor detection
  if (obj.y > 400) {
    obj.y = 400;
    obj.vy = 0;
  }
}
💡 Explanation:
The gravity property defines how fast the object accelerates downward per second.
The static property prevents the engine from applying movement or gravity.

🚀 Creating Objects with Custom Gravity

let rock = instantiateObject({
  name: "Rock",
  type: "gameobject",
  color: "#777",
  x: 200,
  y: 0,
  w: 48,
  h: 48,
  gravity: 800,  // falls faster
  static: false
});

let ground = instantiateObject({
  name: "Ground",
  type: "gameobject",
  color: "#3c3c3c",
  x: 0,
  y: 400,
  w: 512,
  h: 64,
  static: true,   // immovable
  collision: true
});
⚙️ Recommended usage:
– Use gravity for any object that should fall.
– Use static: true for platforms, walls or fixed decorations.
– Combine both with collisions to simulate simple 2D physics.

🧠 Technical Notes

💡 Tip:
A GameObject with static: true and collision: true behaves like a solid block—perfect for building level environments.