Sprite Kit customFieldWithEvaluationBlock - block is not called
I created a new iOS SpriteKit project and added this code to GameScene.m. The block for calculating the force field is never called, so the node is n1
never moved. Does anyone know why? What am I missing?
@implementation GameScene
-(void)didMoveToView:(SKView *)view {
// Create a red circle in the middle of scene
SKShapeNode *n1 = [SKShapeNode shapeNodeWithCircleOfRadius:20];
n1.fillColor = [UIColor redColor];
n1.position = CGPointMake(self.size.width / 2, self.size.height / 2);
n1.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:20];
n1.physicsBody.affectedByGravity = NO;
n1.physicsBody.dynamic = YES;
[self addChild:n1];
// Try to add a custom force field to the scene
SKFieldNode *f1 = [SKFieldNode customFieldWithEvaluationBlock:^vector_float3(vector_float3 position, vector_float3 velocity, float mass, float charge, NSTimeInterval deltaTime) {
printf("block called\n");
vector_float3 res = { 1.0, 0.0, 0.0 };
return res;
}];
f1.enabled = YES;
[self addChild:f1];
}
+3
source to share
No one has answered this question yet
Check out similar questions: