我本来打算把cocos creator打包出来的web程序发布给别人玩,主要涉及的是是
静态的内容,那么就需要一个打开web的服务器,之后浏览器来运行游戏,临时找不到,
直接用golang弄一个代码如下
package main
import (
"fmt"
"net/http"
"os"
"path/filepath"
"strings"
)
func GetCurrentDirectory() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
fmt.Println(err)
}
return strings.Replace(dir, "\\", "/", -1)
}
func main() {
path := GetCurrentDirectory()
http.ListenAndServe(":8080", http.FileServer(http.Dir(path)))
var cmd string
fmt.Scanf("%s", &cmd) // 用于暂停控制台
}
我的资源目录是这样的
main.exe
main.go
└─game
├─res
├─src
├─ index.html
```
game目录就是我放置的静态页面目录
下载地址
https://download.youkuaiyun.com/download/holmes_huang/11175282
额!!!要分,这
加个地址,不知道是否永久啦
链接:https://pan.baidu.com/s/1yw-k4218NFTDj1u5GjwuBA
提取码:5ep2