ユーザー インタラクションのたびに繰り返し呼び出されるノードの SKNode サブクラスを作成しようとしましたが、その後、破壊/爆発効果が発生します。ただし、コードを実行しようとすると、SIGABRT エラーが発生します。___stack_chk_fail
デバッグ端末で行うこと。
さらに、インスペクターでは、SIGABRT のコードが壊れると、これらのプロパティはすべて として表示されnil
ます。
これは私の SKNode サブクラスの .m です:
#import "CandyNode.h"
static const int MAX_VELOCITY = 20;
static const int MIN_VELOCITY = 2;
@implementation CandyNode
- (instancetype)init {
self = [super init];
if (self == [super init])
{
_spriteType = arc4random()%4+1;
NSString* imageRand = [NSString stringWithFormat:@"Sprite %i", _spriteType];
_background = [SKSpriteNode spriteNodeWithImageNamed:imageRand];
_background.name = @"Main";
_background.zPosition = 3;
[self addChild:_background];
_burst1 = [SKSpriteNode spriteNodeWithImageNamed:[NSString stringWithFormat:@"S%dB%d",_spriteType,1]];
_burst2 = [SKSpriteNode spriteNodeWithImageNamed:[NSString stringWithFormat:@"S%dB%d",_spriteType,2]];
_burst3 = [SKSpriteNode spriteNodeWithImageNamed:[NSString stringWithFormat:@"S%dB%d",_spriteType,3]];
_burst1.name = @"Burst #1";
_burst2.name = @"Burst #2";
_burst3.name = @"Burst #3";
[_background setHidden:NO];
[_burst1 setHidden:YES];
[_burst2 setHidden:YES];
[_burst3 setHidden:YES];
[self addChild:_burst1];
[self addChild:_burst2];
[self addChild:_burst3];
double burstAngle[3];
int offsetAngle = 240;
double burstDisplacement[3];
CGVector burstVector[3];
CGFloat x, y;
for (int i = 0; i<=3; i++){
burstAngle[i] = (arc4random()%60+120*i+offsetAngle)*3.1415/180;
burstDisplacement[i] = arc4random()%(MAX_VELOCITY-MIN_VELOCITY)+ MIN_VELOCITY;
x = burstDisplacement[i]*cos(burstAngle[i]);
y = burstDisplacement[i]*sin(burstAngle[i]);
burstVector[i] = CGVectorMake(x, y);
}
_explode1 = [SKAction sequence:@[[SKAction fadeInWithDuration:0],
[SKAction moveBy:burstVector[0] duration:.5],
[SKAction fadeOutWithDuration:.2]]];
_explode2 = [SKAction sequence:@[[SKAction fadeInWithDuration:0],
[SKAction moveBy:burstVector[1] duration:.5],
[SKAction fadeOutWithDuration:.2]]];
_explode3 = [SKAction sequence:@[[SKAction fadeInWithDuration:0],
[SKAction moveBy:burstVector[2] duration:.5],
[SKAction fadeOutWithDuration:.2]]];
}
return self;
}
.h:
#import <SpriteKit/SpriteKit.h>
@interface CandyNode : SKNode
//-(id)initWithImageNumber:(int)spriteType;
//-(void)explodeCandy;
@property (nonatomic) SKSpriteNode *background;
@property (nonatomic) SKSpriteNode *burst1;
@property (nonatomic) SKSpriteNode *burst2;
@property (nonatomic) SKSpriteNode *burst3;
@property (nonatomic) SKAction *explode1;
@property (nonatomic) SKAction *explode2;
@property (nonatomic) SKAction *explode3;
@property (nonatomic) int spriteType;
@end
そして、それはすべてメインの SKScene で呼び出されます: _NodeA = [CandyNode new];
、 _NodeA はそのクラスのヘッダーで次のように定義されています@property (nonatomic) CandyNode *NodeA;
私の質問は明らかに、どうすればこれを機能させることができるか、またはサブクラスと SpriteKit の使用方法についてひどい誤解がある場合、どうすればこれを別の方法で行うことができるでしょうか?