
-
smartvipere75
I have a float2 struct that works perfectly:
class float2(Structure): _fields_ = [('x',c_float),('y',c_float)]```
How can I implement this method of GKPath:
- (instancetype)initWithPoints:(vector_float2 *)points count:(size_t)count radius:(float)radius cyclical:(BOOL)cyclical
Specifically, the problem is when I pass array of float2 to points parameters, app crashes.
Reference:
GKPath initWithPoints:count:radius:cyclical: -
smartvipere75
@dgelessus said:
Ah, that's an auto-generated header from a class dump or something like that. I was looking at the "real" headers from the iOS SDK, which use vector types. (The iOS SDK headers aren't available online, the closest thing you can see is Apple's online documentation for
GKAgent2D.position
.) I'm guessing that during compilation some "magic" happens to properties/methods that use vector types, and the result is what you see in the class dump header. You could try using the methodsposition_
andsetPosition__
(note the extra underscores), which according to the class dump header use structs instead of vector types.Thank you very much, using the methods with underscore solved the problem!
-
smartvipere75
@JonB said:
node.physicsBody().contactTestBitMask=1
in two places (end of your shape creation functions) solves the issue.
contactTestBitMask is mentioned in the description of https://developer.apple.com/documentation/spritekit/skphysicscontactdelegate , and looking at the description shows that it is a way of only responding to contacts that you care about.
Thank you so much for your help! I highly appreciate it, and it’s that situation when code wasn’t working because of simple mistake.
-
smartvipere75
@JonB said:
@dgelessus, are you sure?
Looking at the headers for GKAgent2D, that looks like a normal struct.Exactly, since it’s a a normal struct than what can be wrong with my code?
-
smartvipere75
@dgelessus said:
vector_float2
is a native vector type and not a normal struct. Working with vectors requires different CPU instructions than the ones for normal values.ctypes
doesn't support vector types, so I don't think you can use vector types from Pythonista.Thanks for explanation, sounds like it's impossible but I still have a hope. Can you suggest any possible solution? And also could you please check this post regarding SpriteKit contactDelegate issue:
https://forum.omz-software.com/topic/4267/spritekit-problem -
smartvipere75
Hello, for some reasons the y value of float2 ctypes.Structure doesn’t change. You can run the code from link below and check console. What’s causing this and how to fix it?
Here is a code (line 46):
https://gist.github.com/7f46b31bd43959f937b58a54a24e91a0 -
smartvipere75
Hello, I am opening this topic once again since I still didn't get solution. Basically i’m trying to set contactDelegate on physicsWorld of SKScene that’s created through create_objc_class but it doesn’t work. Any ideas? Thanks in advance.
Here is full code:
https://gist.github.com/anonymous/2530353b2a41c19746bf9c0e0fa9a57fNote:
The code is basically modified version of this:
https://github.com/jbking/pythonista-misc/blob/master/spritekit/skview-demo.py -
smartvipere75
@omz said:
I can't test this right now, but I have a suspicion that you need to set the argtypes and restype properties of the ObjC method manually. The derivation from the protocols argument doesn't always work reliably if the protocol isn't used as part of Pythonista itself. I hope this makes sense.
I completely forgot about argtypes and restype honestly. It makes sense, I will keep trying to find out correct argtypes. Thanks for your suggestion. Please let me know once you test.
-
smartvipere75
@JonB said:
By doesn't work, is it crashing, or just does not receive callbacks?
You might try keeping a copy (rather than alloc.init() inside the function call) -- I am not 100% sure if setting the delegate also increments the retain count, so you might be losing your object before it gets used.I mean it doesn’t receive callbacks, as if I didn’t set delegate. And I posted a link to full code
-
smartvipere75
@omz Here is full code:
https://gist.github.com/anonymous/2530353b2a41c19746bf9c0e0fa9a57fNote:
The code is basically modified version of this:
https://github.com/jbking/pythonista-misc/blob/master/spritekit/skview-demo.py