Ho creato la classe ereditata SKScene
. Il problema è che a contatto del corpo del metodo della fisicadidBeginContact: contatto (SKPhysicsContact *) non invocato
- (void)didBeginContact:(SKPhysicsContact *)contact
non viene richiamato soluzione può essere semplice, ma come principiante con kit sprite mi sono bloccato con questo.
Di seguito si riporta il codice
#import "MyScene.h"
@interface MyScene()
@property BOOL contentCreated;
@end
@implementation MyScene
- (id)initWithSize:(CGSize)size {
self = [super initWithSize:size];
if (self) {
self.physicsWorld.contactDelegate = self;
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
}
return self;
}
- (void)didMoveToView:(SKView *)view
{
if (!self.contentCreated) {
[self buildWorld];
self.physicsWorld.contactDelegate = self;
}
}
#pragma mark - World Building
- (void)buildWorld {
NSLog(@"Building the world");
SKSpriteNode * sprite1 = [[SKSpriteNode alloc] initWithColor:[SKColor grayColor] size:CGSizeMake(100,100)];
sprite1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(100,100)];
sprite1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) +100);
SKSpriteNode * sprite2 = [[SKSpriteNode alloc] initWithColor:[SKColor grayColor] size:CGSizeMake(100,100)];
sprite2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(100,100)];
sprite2.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 100);
[self addChild:sprite1];
[self addChild:sprite2];
}
- (void)didBeginContact:(SKPhysicsContact *)contact
{
NSLog(@"contact");
}
@end
Grazie in anticipo.
@Alexander cadono giù per toccarsi – raheem52