Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Vec2

Represents a 2D vector with x and y components. Used throughout the SDK for screen coordinates, UI positioning, 2D mathematical operations, and coordinate system conversions.

Type Definition

interface Vec2 {
    x: number;
    y: number;
}

Properties

  • x: The horizontal coordinate or x-component of the vector
  • y: The vertical coordinate or y-component of the vector

Examples

Basic Usage

// Screen coordinates
const mousePosition: Vec2 = {x: 150, y: 200};
const screenCenter: Vec2 = {x: 1920 / 2, y: 1080 / 2};

// 2D offset or direction
const offset: Vec2 = {
    x: mousePosition.x - screenCenter.x,
    y: mousePosition.y - screenCenter.y
};
  • Vec3 - 3D vector extension of Vec2
  • Transform - Uses Vec3 internally for translation
  • Rect - Uses Vec2 concepts for 2D bounds
  • Cameras - Coordinate system conversions using Vec2
  • Effects - 2D positioning for visual effects
  • Webviews - UI positioning and layout