gpt4 book ai didi

ios - Rubymotion 和结构指针

转载 作者:技术小花猫 更新时间:2023-10-29 10:53:32 26 4
gpt4 key购买 nike

我正在试验 cocosmotion,Cocos2d 的 Rubymotion 实现。在我正在学习的教程中,我有一个将结构作为参数的方法。我查阅了 Rubymotion 和 MacRuby 文档,但无法弄清楚如何根据我需要的结构实例化一个新对象。我认为主要问题是该结构以小写字母开头,而当我尝试使用它时,Ruby 认为它是一个局部变量。

我相信我遇到了与此处所述相同的问题: https://github.com/MacRuby/MacRuby/issues/121

是否有解决方案或解决方法?

该结构在 Objective-C 中定义如下:

 typedef struct _ccTexParams {
GLuint minFilter;
GLuint magFilter;
GLuint wrapS;
GLuint wrapT;
} ccTexParams;

我尝试调用的方法需要一个 ccTexParams 结构。

这是我尝试过的:

            @mysprite = Pointer.new("{ccTexParams=
{GLUint=GL_LINEAR_MIPMAP_LINEAR}
{GLUint=GL_LINEAR}
{GLUint=GL_CLAMP_TO_EDGE}
{GLUint=GL_CLAMP_TO_EDGE}}", 4)

当我这样尝试时:

        @mysprite = Pointer.new(:object, 4)

@mysprite[0] = GL_LINEAR_MIPMAP_LINEAR
@mysprite[1] = GL_LINEAR
@mysprite[2] = GL_CLAMP_TO_EDGE
@mysprite[3] = GL_CLAMP_TO_EDGE

运行时错误是:

expected instance of Pointer of type `{_ccTexParams=IIII}', got `@' (TypeError)

我也试过:

@mysprite = Pointer.new("_ccTexParams", 4)

@mysprite[0] = GL_LINEAR_MIPMAP_LINEAR
@mysprite[1] = GL_LINEAR
@mysprite[2] = GL_CLAMP_TO_EDGE
@mysprite[3] = GL_CLAMP_TO_EDGE

错误:

Can't find pointer description for type `_ccTexParams'

我还尝试以多种不同的方式将其替换为 CcTexParams、_ccTexParams 和 ccTexParams,但没有任何版本有效。

我试过这个:

@mysprite = CcTexParams.new
@mysprite.minFilter = GL_LINEAR_MIPMAP_LINEAR
@mysprite.magFilter = GL_LINEAR
@mysprite.wrapS = GL_CLAMP_TO_EDGE
@mysprite.wrapT = GL_CLAMP_TO_EDGE

RubyMotion 提示它 expected an instance of Pointer, got '#<CcTexParams minFilter=9987 magFilter=9729 wrapS=33071 wrapT=33071>' (CcTexParams) (TypeError)

我试过只传递 [GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE]直接上方法。它提示它 expected a Pointer but got an Array .

也许我应该重命名 ccTexParams在 lib 中类似于 CCTexParams ?我猜这不是一个理想的解决方法。

最佳答案

如果有人正在为此寻找解决方案,请尝试 Joybox .它是 Cocos2D 的包装器。

Joybox combines the most popular and widely used 2D game engine for iOS, Cocos2D, folds in the amazing Box2D physics engine, and then wraps them up into a clean Ruby API that will make game development faster and more enjoyable for both beginners and experts alike.

关于ios - Rubymotion 和结构指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12886349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com