I'm experimenting with cocosmotion, a Rubymotion implementation of Cocos2d. In the tutorial I'm working through, I have a method that takes a struct as an argument. I consulted the Rubymotion and MacRuby docs, but can't figure out how to instantiate a new object based on the struct I need. I think the main issue is that the struct starts with a lowercase letter and Ruby thinks it's a local variable when I try to work with it.
I believe I have the same problem as stated here: https://github.com/MacRuby/MacRuby/issues/121
Is there a solution or workaround?
The struct is defined in Objective-C like so:
typedef struct _ccTexParams {
GLuint minFilter;
GLuint magFilter;
GLuint wrapS;
GLuint wrapT;
} ccTexParams;
The method I'm trying to call expects a ccTexParams struct.
Here is what I've tried:
@mysprite = Pointer.new("{ccTexParams=
{GLUint=GL_LINEAR_MIPMAP_LINEAR}
{GLUint=GL_LINEAR}
{GLUint=GL_CLAMP_TO_EDGE}
{GLUint=GL_CLAMP_TO_EDGE}}", 4)
When I try it this way:
@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
The runtime error is:
expected instance of Pointer of type `{_ccTexParams=IIII}', got `@' (TypeError)
I also tried:
@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
The error:
Can't find pointer description for type `_ccTexParams'
I've also tried to replace it as CcTexParams, _ccTexParams, and just ccTexParams in a bunch of different ways, no versions of it work.
I tried this:
@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 complains it expected an instance of Pointer, got '#<CcTexParams minFilter=9987 magFilter=9729 wrapS=33071 wrapT=33071>' (CcTexParams) (TypeError)
I tried just passing [GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE]
directly to the method. It complains that it expected a Pointer but got an Array
.
Perhaps I should just rename ccTexParams
in the lib to something like CCTexParams
? I'm guessing that's not an ideal workaround.
If someone's looking for a solution for this, try Joybox. It's a wrapper for 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With