Instantiating a ConstNFloatPtr

Instantiating a ConstNFloatPtr

Hello, I am trying to use the CGContextSetLineDash function from the CoreGraphics library to draw a dashed line.  One argument of this function is a ConstNFloatPtr, which, I believe, is basically just a wrapper around an array of floats.  Unfortunately, I can't for the life of me figure out how to instantiate one.

In Obj-C, it's as simple as:

float dashLengths[] = {30, 30};
CGContextSetLineDash(context, 0, dashLengths, 20.0);

Though with Multi-OS Engine, similar code does not work (Error: incompatible types: float[] cannot be converted to ConstNFloatPtr).

After digging for a little while, I have discovered that there is a ConstNFloatPtrImpl class, accessible through the PtrImplementer class...  Though I can't seem to make use of it.  

Does anyone know what needs to be done to use the CGContextSetLineDash function?   Thank you.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Dear Anthony,

You can use the PtrFactory class for this.

NFloatPtr lengths = PtrFactory.newNFloatArray(new double[]{30.0, 30.0});
CGContextSetLineDash(context, 0, lengths, 2);

Best Regards,
Kristóf

It looks like that works perfectly for me, thank you for the quick response!

Leave a Comment

Please sign in to add a comment. Not a member? Join today