Skip to content

The JavaScript game engine that feels like home for Unity developers. Build 2D games with familiar GameObject-Component architecture, physics, animations, and input handling - all in vanilla JavaScript with zero dependencies.

Notifications You must be signed in to change notification settings

RicardoRibeirorr/NityJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ NityJS - Unity's Power in Pure JavaScript

"From C# to JavaScript - Same patterns, zero learning curve!"

The JavaScript game engine that feels like home for Unity developers. Build 2D games with familiar GameObject-Component architecture, physics, animations, and input handling - all in vanilla JavaScript with zero dependencies.

License: MIT Build Status JavaScript Documentation

๐Ÿš€ Why Choose NityJS?

For Unity Developers

  • ๐ŸŽฏ Instant Familiarity - GameObject, Component, Scene... exactly what you know
  • ๐Ÿ”„ Same Patterns - Start(), Update(), OnCollisionEnter() - it's all here
  • ๐Ÿ“ฆ Component-Based - Add/remove functionality just like Unity prefabs
  • ๐ŸŽจ Visual Scripting - Write code the Unity way, run it in the browser

For Web Developers

  • โšก Zero Dependencies - Pure JavaScript, no libraries needed
  • ๐Ÿ“ฑ Cross-Platform - Works everywhere JavaScript runs
  • ๐Ÿ”ง Easy Integration - Drop into any web project instantly
  • ๐Ÿ“ฆ Dual Distribution - ES6 modules OR global objects

For Everyone

  • ๐ŸŽ“ Learn Game Development - Perfect stepping stone into game programming
  • โšก Rapid Prototyping - From idea to playable in minutes
  • ๐Ÿ—๏ธ Production Ready - Stable collision system, optimized performance
  • ๐Ÿ“– Comprehensive Docs - Every class documented with examples

โœจ Features That Unity Developers Will Love

// Looks familiar? That's the point! ๐Ÿ˜Š
class Player extends GameObject {
    constructor() {
        super("Player");
        
        // Add components just like Unity
        this.addComponent(new SpriteRendererComponent("player", "idle"));
        this.addComponent(new RigidbodyComponent());
        this.addComponent(new BoxColliderComponent(32, 32));
        this.addComponent(new PlayerController());
    }
}

// Unity-style Destroy system - exactly what you expect!
Destroy(player);                              // Destroy GameObject
DestroyComponent(player, RigidbodyComponent);  // Remove specific component
DestroyAll();                                 // Clear entire scene

// Metadata-driven components - ALL components support this!
const playerSprite = SpriteRendererComponent.meta({
    spriteName: "player_idle",
    width: 64,
    height: 64,
    opacity: 0.9,
    color: "#FF6B6B",
    flipX: true,
    flipY: false
});

const physics = RigidbodyComponent.meta({
    gravity: true,
    gravityScale: 400,
    bounciness: 0.2
});

const collider = BoxColliderComponent.meta({
    width: 32,
    height: 48,
    trigger: false
});

// Animation clips with metadata too!
const walkClip = SpriteAnimationClip.meta({
    name: "walk",
    spriteNames: ["player:walk_0", "player:walk_1", "player:walk_2"],
    fps: 8,
    loop: true
});

// Perfect for visual editors and JSON scene files
const componentData = {
    type: "SpriteRendererComponent",
    metadata: {
        spriteName: "enemy_walk",
        width: 48,
        height: 48,
        color: "#FF6B6B",
        opacity: 0.8
    }
};

// ALL 8 components + SpriteAnimationClip support metadata:
// SpriteRenderer, Image, Shape, Rigidbody, BoxCollider, 
// CircleCollider, SpriteAnimation, Camera + SpriteAnimationClip!

// Component - the new MonoBehavior but with more style! ๐Ÿ˜Š
class PlayerController extends Component {
    start() {
        this.speed = 200;
        this.jumpForce = 400;
    }
    
    update() {
        // Input handling you already know
        if (Input.isKeyDown('Space')) {
            this.jump();
        }
        
        // Frame-rate independent movement
        const moveX = Input.isKeyDown('d') ? 1 : 0 - Input.isKeyDown('a') ? 1 : 0;
        this.rigidbody.velocity.x = moveX * this.speed;
    }
    
    onCollisionEnter(collision) {
        if (collision.gameObject.hasTag("Enemy")) {
            this.takeDamage();
        }
    }
}

๐Ÿ› ๏ธ Core Systems

System Unity Equivalent Status
GameObject-Component GameObject/MonoBehaviour โœ… Complete
Unity-Style Destroy Destroy/DestroyImmediate โœ… Complete
Layer System Sorting Layers/Canvas โœ… Complete
Metadata Components Editor Inspector โœ… Complete
Scene Management Scene System โœ… Complete
Physics & Collision Rigidbody2D/Collider2D โœ… Stable
Input System Input Manager โœ… Enhanced
Sprite Animation Animator/Animation โœ… Complete
Asset Management Resources/AssetDatabase โœ… Complete
Time & Delta Time.deltaTime โœ… Complete
Tilemap System Tilemap/TilemapRenderer โœ… Complete
Audio System AudioSource/AudioListener โœ… Complete

๐Ÿ“š Comprehensive Documentation

Everything is documented! From beginner tutorials to advanced patterns:

๐ŸŽฏ Getting Started

๐Ÿ”ง Core Systems

โšก Advanced Features

  • Universal Metadata Support - All 8 component types + SpriteAnimationClip support metadata creation
  • JSON Scene Serialization - Perfect for visual editors and level designers
  • Unity-Style Validation - Type-safe metadata with helpful error messages
  • Static Factory Methods - Component.meta() for declarative creation
  • Runtime Metadata Application - Update components with applyMeta()
  • Backward Compatibility - Traditional constructors still work perfectly

๐ŸŽฎ By Game Type

  • Platformers - Player movement, collision, gravity
  • Puzzle Games - Input handling, state management
  • Action Games - Fast collision, animations, effects
  • Physics Simulations - Realistic movement and forces

๐Ÿš€ Advanced Topics

  • Performance Optimization - Object pooling, efficient rendering
  • Architecture Patterns - Component composition, state machines
  • Integration - Embedding in web apps, build systems

๐Ÿš€ Quick Start

Build Commands

npm install
npm run build        # Build all versions (dev + prod)
npm run build:dev    # Development builds only (readable code)
npm run build:prod   # Production builds only (minified)

Build Outputs

  • dist/nity.js - IIFE format, non-minified (development, browser script tags)
  • dist/nity.min.js - IIFE format, minified (production, browser script tags)
  • dist/nity.module.js - ES6 modules, non-minified (development, modern apps)
  • dist/nity.module.min.js - ES6 modules, minified (production, modern apps)

Your First Game (Unity Style!)

import { Game, Scene, GameObject, SpriteAsset, SpritesheetAsset, SpriteRendererComponent, ShapeComponent, Destroy } from './dist/nity.module.min.js';

// Create game (like Unity's Game window)
const canvas = document.getElementById('gameCanvas');
const game = new Game(canvas);

// Create scene (like Unity's Scene)
const gameScene = new Scene({
  create() {
    // Load assets - they register automatically!
    new SpriteAsset("player", "assets/player.png");
    new SpritesheetAsset("enemies", "assets/enemies.png", {
      spriteWidth: 32,
      spriteHeight: 32,
      columns: 4,
      rows: 2
    });

    // Create player (like Unity's GameObject)
    const player = new GameObject("Player");
    player.position.set(100, 100);
    
    // Add sprite component (like Unity's AddComponent)
    player.addComponent(new SpriteRendererComponent("player"));
    
    // Create shape with metadata (perfect for visual editors!)
    const enemy = new GameObject("Enemy");
    enemy.position.set(200, 100);
    
    // Multiple component creation methods:
    // 1. Traditional constructor
    enemy.addComponent(new ShapeComponent("circle", { radius: 25, color: "red" }));
    
    // 2. Metadata-driven (ideal for editors)
    const healthBar = ShapeComponent.meta({
        shapeType: "rectangle",
        options: {
            width: 50,
            height: 8,
            color: "#00FF00",
            filled: true
        }
    });
    
    // 3. All components support metadata factory
    const camera = CameraComponent.meta({ zoom: 1.5 });
    const animation = SpriteAnimationComponent.meta({ 
        defaultClipName: "idle", 
        autoPlay: true 
    });
    
    // 4. Animation clips with metadata
    const idleClip = SpriteAnimationClip.meta({
        name: "idle",
        spriteNames: ["player:idle_0", "player:idle_1"],
        fps: 4,
        loop: true
    });
    
    // Unity-style destruction
    setTimeout(() => {
      Destroy(enemy);  // Just like Unity!
    }, 3000);
    
    // Add to scene (like Unity's Instantiate)
    Instantiate.create(player);
    Instantiate.create(enemy);
  }
});

// Enable Layer System (like Unity's Sorting Layers)
game.configure({
    useLayerSystem: true  // Enables 3 default layers: background, default, ui
});

// Objects automatically go to 'default' layer, or set explicitly:
// background.layer = 'background';  // Background objects
// ui.layer = 'ui';                  // UI elements

// Launch game (like Unity's Play button)
game.launch(gameScene);

๐ŸŽฏ Examples & Demos

Explore complete game examples in the examples/ directory:

Each example includes:

  • โœ… Fully commented code
  • โœ… Step-by-step explanations
  • โœ… Unity comparison notes
  • โœ… Live demos (where applicable)

๐Ÿค Looking for Collaborators!

Help us make NityJS the go-to JavaScript game engine!

๐ŸŽฏ What We Need

  • Unity Developers - Help us perfect the Unity-like experience
  • Web Developers - Optimize for modern web standards
  • Game Designers - Create example games and tutorials
  • Documentation Writers - Improve guides and examples
  • Performance Engineers - Optimize rendering and physics
  • Community Builders - Grow the ecosystem

๐Ÿš€ How to Contribute

  1. โญ Star this repo - Show your support!
  2. ๐Ÿ› Report issues - Found a bug? Let us know!
  3. ๐Ÿ’ก Suggest features - What would make this better?
  4. ๐Ÿ“ Improve docs - Help others learn faster
  5. ๐ŸŽฎ Build games - Show what's possible!
  6. ๐Ÿ”ง Submit PRs - Code contributions welcome!

๐Ÿ’ฌ Join the Community

  • GitHub Discussions - Share ideas and get help
  • Issue Tracker - Report bugs and request features
  • Pull Requests - Contribute code and documentation

๐ŸŽฏ Roadmap

โœ… Current (v1.0)

  • Complete GameObject-Component system
  • Stable physics and collision detection
  • Comprehensive input handling system
  • Sprite animation system with metadata support
  • Tilemap system for tile-based level design
  • Layer system with OffscreenCanvas optimization
  • Universal metadata support for all components
  • Enhanced ShapeComponent with polygon support
  • Browser compatibility detection and polyfills
  • Audio system with 3D spatial audio and procedural generation
  • Comprehensive documentation and examples

๐Ÿšง Coming Next (v1.1)

  • Particle System - Visual effects and animations
  • Raycast System - Physics raycasting for line-of-sight and collision detection
  • Mobile Touch - Touch input and gestures for mobile devices
  • Debug Tools - Visual debugging and performance profilers
  • Visual Editor - Browser-based scene editor with metadata integration

๐ŸŒŸ Future (v2.0+)

  • 3D Support - Basic 3D rendering capabilities
  • Advanced Editor - Full visual scripting with metadata system
  • Plugin System - Extend engine functionality
  • WebXR Support - VR/AR game development
  • Performance Profiler - Built-in optimization tools

๐Ÿ“ˆ Performance & Compatibility

  • โšก Lightweight - ~23KB minified
  • ๐Ÿ”ง Zero Dependencies - Pure JavaScript
  • ๐ŸŒ Universal - Works in all modern browsers
  • ๐Ÿ“ฑ Mobile Ready - Touch-optimized input
  • โš™๏ธ Node.js Compatible - Server-side game logic

Browser Support

  • Chrome/Edge: Full support (recommended)
  • Firefox: Full support
  • Safari: Full support (iOS 16.4+ for LayerManager)
  • Mobile Browsers: Full support on modern devices
  • Legacy Support: Automatic fallbacks for older browsers

Layer System Compatibility

  • OffscreenCanvas: Chrome 69+, Firefox 105+, Safari 16.4+
  • Fallback Mode: Graceful degradation to single canvas rendering
  • Detection: Automatic capability detection with console warnings

๐Ÿ“„ License

MIT License - Use it anywhere, build anything!

๐Ÿ™ Credits

Built with โค๏ธ for the game development community. Inspired by Unity's elegance and the web's accessibility.


๐ŸŽฎ Ready to Build Your Game?

๐Ÿ“– Start with the Documentation | ๐ŸŽฏ Try the Examples | ๐Ÿค Join the Project

"The game engine that speaks Unity, thinks JavaScript, and runs everywhere."

About

The JavaScript game engine that feels like home for Unity developers. Build 2D games with familiar GameObject-Component architecture, physics, animations, and input handling - all in vanilla JavaScript with zero dependencies.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published