使用NDK和cgo和/或SWIG或类似工具,可以在Go语言中构建Android游戏吗?

huangapple go评论80阅读模式
英文:

Is is possible to build Android games in Go using the NDK with cgo and/or SWIG or similar?

问题

有没有可能完全使用Go来构建Android游戏?我并不固守主题行中提到的技术。我知道有些人用Go构建了一些Android程序,但它们可能是无界面的。

英文:

Is it possible to use Go to build Android games at all? I'm not wedded to the technologies mentioned in the subject line. I know that some people have built some Android programs in Go, but they may have been headless.

答案1

得分: 1

不,现在不可能。Go和C程序可以通过cgo进行互操作。但在这种情况下,Go程序必须在将控制权传递给基于C的部分之前启动和初始化其运行时。

在Android中使用NDK时,您的C代码是由Dalvik虚拟机通过dlopen调用的。因此,Go运行时将没有机会初始化自身。

英文:

No, it is not possible right now. Go and C programs can interoperate via cgo. but in that case, the Go program has to start and initialize its runtime before passing control to the C-based part of the program.

When using the NDK in Android, your C code is called by the Dalvik virtual machine via dlopen. So the Go runtime would not have a chance to initialize itself.

答案2

得分: -1

如果你想要非无头应用程序,我的建议是使用cgo来进行GUI开发。这听起来有些违反直觉,但如果NDK支持C的Android GUI库,使用这些调用来编写GUI可能是最简单的方法。当然,你不必将所有逻辑都用C来编写。你可以为每个GUI调用编写cgo包装器,然后在Go中编写GUI,只是每个GUI调用都会通过cgo进行转换。

英文:

If you want non-headless apps, my advice would be to use cgo for the GUI. That sounds counterintuitive, but if the NDK supports C android gui libraries, it'd probably be easiest to write the GUI using those calls. Of course, you don't have to write all the logic in C. You could simply cgo wrappers for each of the GUI calls and then write the GUI in go, except that each gui call would be translated through cgo.

huangapple
  • 本文由 发表于 2012年7月6日 05:08:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/11352592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定