如何将C ++游戏嵌入网页?

时间:2012-05-09 09:05:19

标签: c++ embed

无需在flash中重新编码或将其变成java applet! 将其保留为C ++应用,有没有办法将其嵌入到网页中,以便网站访问者可以玩游戏?

我们可以假设它是一款小型游戏,平均闪存游戏的大小甚至更薄。

有问题的游戏是使用Allegro库编写的1000行代码。

有可能吗?

4 个答案:

答案 0 :(得分:5)

快速回答:你不能。

C ++应用程序无法嵌入到网页中,需要下载,用户必须在客户端计算机上运行它们。

详细信息:它在某种程度上是可能的,但绝对不能跨浏览器移植。例如,Internet Explorer具有 ActiveX 组件(它们可以是C ++应用程序,它将被下载,安装并将在网页内运行)。其他浏览器有不同的机制来实现这一点(例如Chrome有 Native Client ),但你不能写一些真正可移植的东西,无论你使用什么,你都会有很多限制。

答案 1 :(得分:3)

答案 2 :(得分:2)

Try the emscripten project, it is a C++ compiler based on LLVM Clang and compiles C++ files into JS files which can then be run in the browser.

#include <iostream>

int main()
{
    using namespace std;

    cout << "Hello World" << endl;
    return 0;
}

Assuming that you saved this in helloWorld.cpp use this after installing Emscripten.

$ emcc helloWorld.cpp -o helloWorld.html

You will be done, open helloWorld.html now in your browser and see for yourself. The good thing about Emscripten is that it supports a wide range of desktop libraries, including SDL etc.,

http://kripken.github.io/emscripten-site/

答案 3 :(得分:0)

只能将Google Chrome浏览器的插件作为原生扩展程序。