最近很火的小霸王游戏机模拟开源项目--JSNES
开源地址:https://github.com/bfirsh/jsnes
一、简介:
Jsnes是一个用 JavaScript 实现的 NES 模拟器;这是一个可以在浏览器和 Node.js 中使用的库,浏览器的用户界面可以在 https://github.com/bfirsh/jsnes-web 中找到。
二、Installation 安装
1. 对于 Node.js 或 Webpack:
$ npm install jsnes
或者使用
$ yarn add jsnes
2.在浏览器中,你可以使用 unpkg:
<script type="text/javascript" src="https://unpkg.com/jsnes/dist/jsnes.min.js"></script>
三、Usage 用法
// Initialize and set up outputs
var nes = new jsnes.NES({
onFrame: function(frameBuffer) {
// ... write frameBuffer to screen
},
onAudioSample: function(left, right) {
// ... play audio sample
}
});
// Read ROM data from disk (using Node.js APIs, for the sake of this example)
const fs = require('fs');
var romData = fs.readFileSync('path/to/rom.nes', {encoding: 'binary'});
// Load ROM data as a string or byte array
nes.loadROM(romData);
// Run frames at 60 fps, or as fast as you can.
// You are responsible for reliable timing as best you can on your platform.
nes.frame();
nes.frame();
// ...
// Hook up whatever input device you have to the controller.
nes.buttonDown(1, jsnes.Controller.BUTTON_A);
nes.frame();
nes.buttonUp(1, jsnes.Controller.BUTTON_A);
nes.frame();
// ...
四、Build 构建
如果想要构建好一个发布版,可以执行:
$ yarn run build
(这会在目录下创建 dist/jsnes.min.js 文件)
五、Running tests 运行测试
$ yarn test
六、以下是演示链接,兼容PC端、移动端:
版权声明:若无特殊注明,本文为《Chin》原创,转载请保留文章出处。
本文链接:https://www.qinor.cn/post-65.html
正文到此结束





西西