我试图创建一个 SKlabelNode,每次调用场景时都会显示随机文本。我觉得我做的一切都是正确的,但是当进入这个场景时游戏崩溃并返回一个以 EXC_ARITHMETIC 开头的绿色错误。我自学数组,不知道我做错了什么?
。H
#import <SpriteKit/SpriteKit.h>
@interface EndScene : SKScene{
NSMutableArray *TextArray;
}
@end
.m
#import "EndScene.h"
#import "MyScene.h"
SKLabelNode *myLabel;
@implementation EndScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.scaleMode = SKSceneScaleModeAspectFill;
self.backgroundColor = [SKColor blackColor];
[self setupLabel];
[self RandomText];
[self loadText];
}
return self;
}
- (void) RandomText
{
int randomNumber = arc4random() % TextArray.count;
myLabel.text = [NSString stringWithFormat:@"%@",[TextArray objectAtIndex:randomNumber]];
}
- (void) loadText
{
TextArray = [[NSMutableArray alloc] init];
[TextArray addObject:@"End Of Game Text"];
[TextArray addObject:@"End Text 2"];
}
-(void) setupLabel{
myLabel = [SKLabelNode labelNodeWithFontNamed:@"Academy Engraved LET"];
myLabel.fontSize = 44;
myLabel.zPosition = 0;
myLabel.position = CGPointMake(390, 660);
[self addChild:myLabel];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKScene *myScene = [[MyScene alloc]initWithSize:self.size];
SKTransition *doors = [SKTransition crossFadeWithDuration:5];
[self.view presentScene:myScene transition:doors];
}
@end