将对象发送到 Android 中的库类

发布于 2024-09-16 17:32:34 字数 433 浏览 1 评论 0原文

我正在尝试在 android 中制作一个简单的自制游戏引擎/框架。我将“引擎”作为一个库项目来处理所有图形渲染、游戏活动等。本质上,库项目有一个 GameMain 类,它有一个背景图像、一个可绘制对象数组和一些函数(最重要的是 run() 函数)。使用此库的项目使用自己独特的 run() 函数扩展此类。这个想法是,使用引擎的游戏从自己的 Activity 开始,从库中启动 GameActivity,并将其唯一的 GameMain 子对象传递到库中,由于多态性,该对象应该运行唯一的 run() 方法。

然而,让它发挥作用却是一场斗争。我最初尝试使 GameMain 可序列化,但这似乎不起作用。我现在尝试将其设为 Parcelable,但从库调用时它似乎不会运行子对象 run() 函数。我想知道,Parcelable 对象实际上能够跨活动发送对象方法吗?我是否以错误的方式处理这个问题,或者我只是有一些其他我没有发现的奇怪的错误?

I'm attempting to make a simple homebrew game engine/framework in android. I have the "engine" as a library project that handles all of the graphics rendering, game activity, and whatnot. Essentially, the library project has a class GameMain which has a background image, an array of drawables, and a few functions (the most important is a run() function). The projects that use this library extend this class with their own unique run() function. The idea is that games that use the engine start with their own activity, launch the GameActivity from the library, and pass their unique GameMain child object into the library, which should run the unique run() method thanks to polymorphism.

Getting this to work, however, has been a struggle. I originally attempted to make the GameMain Serializable, which didn't appear to work. I'm now attempting to make it a Parcelable, but it does not appear to run the child objects run() function when called from the library. I'm wondering, are Parcelable objects actually capable of sending Object methods across activities? Am I going about this the wrong way, or am I just having some other weird bug I have not uncovered?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2024-09-23 17:32:34

为什么不让用户扩展 GameActivity 来传递他们的游戏呢?

Why don't let the users extend GameActivity to pass their game?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文