Project Icon

melonJS

现代化HTML5游戏引擎 全面支持ES6

melonJS是一款现代化的HTML5游戏引擎,采用ES6完全重构。它提供2D精灵图形、WebGL渲染、物理引擎和碰撞检测等核心功能。支持Tiled地图编辑器,兼容主流浏览器和移动设备。集成TexturePacker、Spine等开发工具。可通过npm安装或CDN直接使用。适合开发各类2D网页游戏。

melonJS 2

melonJS Logo

Build Size Tree-shaking NPM Package jsDeliver Boss Bounty Badge Contributor Covenant

A fresh, modern & lightweight HTML5 game engine

melonJS

melonJS 2 is a modern version of the melonJS game engine that was first released in 2011. It has been rebuilt entirely using ES6 class, inheritance and semantic, and bundled using esbuild for blazing fast build performance and provide modern features such as tree-shaking.

Note: migrating an existing project to melonJS 2 (version 10.0 and higher) will definitely break your game (ES6 semantic and inheritance, nodeJS event emitter, and no backward compatibility with deprecated legacy APIs), and you might want to read first this small step by step guide on upgrading to melonJS 2. If you are looking at the legacy version (9.x and lower) of melonJS, you can find it here under the legacy branch.

melonJS is open-source, licensed under the MIT License, and actively developed and maintained with the help of a small team of enthusiasts at AltByte in Singapore.

About melonJS

melonJS is a fully featured game engine :

Compatibility

  • Standalone library (does not rely on anything else, except a HTML5 capable browser)
  • Compatible with all major browsers (Chrome, Safari, Firefox, Opera, Edge) and mobile devices

Graphics

  • 2D sprite-based graphic engine
  • Blazing Fast WebGL renderer for desktop and mobile devices with fallback to Canvas rendering
  • High DPI resolution & Canvas advanced auto scaling
  • Sprite with 9-slice scaling option, and animation management
  • built-in effects such as tinting and masking
  • Standard spritesheet, single and multiple Packed Textures support
  • System & Bitmap Text

Sound

  • Web Audio support with 3D spatial audio or stereo panning based on Howler
  • fallback to Multi-channel HTML5 audio for legacy browsers

Physic

  • Polygon (SAT) based collision algorithm for accurate detection and response
  • Fast Broad-phase collision detection using spatial partitioning
  • Collision filtering for optimized automatic collision detection

Input

  • Mouse and Touch device support (with mouse emulation)
  • Device motion & accelerometer support

Level Editor

  • Tiled map format version +1.0 built-in support for easy level design
    • Uncompressed and compressed Plain, Base64, CSV and JSON encoded XML tilemap loading
    • Orthogonal, Isometric and Hexagonal maps (both normal and staggered)
    • Multiple layers (multiple background/foreground, collision and Image layers)
    • Animated and multiple Tileset support
    • Tileset transparency settings
    • Layers alpha and tinting settings
    • Rectangle, Ellipse, Polygon and Polyline objects support
    • Tiled Objects
    • Flipped & rotated Tiles
    • Dynamic Layer and Object/Group ordering
    • Dynamic Entity loading
    • Shape based Tile collision support

Assets

  • Asynchronous asset loading
  • A fully customizable preloader

And Also

  • A state manager (to easily manage loading, menu, options, in-game state)
  • Tween Effects, Transition effects
  • Pooling support for object recycling
  • Basic Particle System
  • nodeJS EventEmitter based event system

Tools integration

melonJS is supporting the below tools and frameworks natively or through our official plugin(s) :

Free Texture Packer TexturePacker PhysicsEditor ShoeBox Tiled Cordova Spine aseprite

Tools integration and usage with melonJS is documented in our Wiki.

Using melonJS

For your first time using melonJS, this is where you start

You may find it useful to skim the overview found at the wiki Details & Usage

When starting your own projects, checkout our ES6 x Vite boilerplate or the TypeScript x Vite boilerplate

Demos

A few demos of melonJS capabilities :

More examples are available here


Basic Hello World Example

import * as me from "https://esm.run/melonjs";

me.device.onReady(function () {
    // initialize the display canvas once the device/browser is ready
    if (!me.video.init(1218, 562, {parent : "screen", scale : "auto"})) {
        alert("Your browser does not support HTML5 canvas.");
        return;
    }

    // set a gray background color
    me.game.world.backgroundColor.parseCSS("#202020");

    // add a font text display object
    me.game.world.addChild(new me.Text(609, 281, {
        font: "Arial",
        size: 160,
        fillStyle: "#FFFFFF",
        textBaseline : "middle",
        textAlign : "center",
        text : "Hello World !"
    }));
});

Simple hello world using melonJS 2 (version 10.x or higher)

Documentation

Plugins

melonJS provide a plugin system allowing to extend the engine capabilities.

Here is the list of official plugins maintained by the melonJS team:

If you wish to develop your own plugin, we also provide a plugin template to help you get started.

Download melonJS

The latest builds with corresponding release note are available for direct download here.

melonJS 2 now only provides an ES6 Bundle :

builddescription
index.jsa tree-shakeable ES6 Module Directory
index.d.tstypescript declaration files

Note: if you need your application to be compatible with ES5, refer to our boilerplate that provides automatic transpiling to ES5.

The latest version of melonJS can be installed through NPM :

$ npm install melonjs

And then import melonjs in your project using :

$ import * as me from 'melonjs';

Or it can simply be added to your html, using jsDeliver content delivery network (CDN) :

<!-- load the ES6 module bundle of melonJS v10.0 -->
<script type="module" src="https://esm.run/melonjs@10.0"></script>
<!-- omit the version completely to get the latest one -->
<!-- you should NOT use this in production -->
<script type="module" src="https://esm.run/melonjs"></script>

Note: starting from the 10.0.0 version, the debug plugin is no longer provided as part of the melonJS library release, and has been moved to the official boilerplate

Contributing

For most users, all you probably want is to use melonJS, and all you need then is just to download the latest built release to get started.

If you want to start to be part and contribute to the project, make sure to read our Contributing Guide before starting submitting changes or new features.

Contributors

Sponsors

Support the development of melonJS by becoming a sponsor. Get your logo in our README with a link to your site or become a backer and get your name in the BACKERS list. Any level of support is really appreciated and goes a long way !

Melon Gaming

[![Altbyte Pte Ltd](https://user-images.githubusercontent.com/4033090/136692693-35dca8aa-5012-4a37-9ea2-51640d2e6d73.png

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号