Ios8 iOS 8中绘图应用程序的SpriteKit渲染问题

Ios8 iOS 8中绘图应用程序的SpriteKit渲染问题,ios8,sprite-kit,xcode6,Ios8,Sprite Kit,Xcode6,我有一个在iOS 7中可以正常工作的绘图模拟场景,但在iOS 8中却无法正常工作。这是针对模拟器和设备的 场景应该在手指接触屏幕的地方显示黑线,并且它们应该在您完成“绘制”一条线后保持不变。以下是iOS 7中的屏幕截图: 虽然没有崩溃,但在iOS 8中这些线根本不会渲染。我只是得到一张空白画布。NSLogging表示它确实正确注册了ToucheSBegind/Moved/End函数 我制作了整个班级的全部内容: @implementation CSDraw -(id)initWithSize

我有一个在iOS 7中可以正常工作的绘图模拟场景,但在iOS 8中却无法正常工作。这是针对模拟器和设备的

场景应该在手指接触屏幕的地方显示黑线,并且它们应该在您完成“绘制”一条线后保持不变。以下是iOS 7中的屏幕截图:

虽然没有崩溃,但在iOS 8中这些线根本不会渲染。我只是得到一张空白画布。NSLogging表示它确实正确注册了ToucheSBegind/Moved/End函数

我制作了整个班级的全部内容:

@implementation CSDraw

-(id)initWithSize:(CGSize)size type:(NSString *)CSType stresslevel:(NSInteger)stress_indicator { //designated initializer
    if (self = [super initWithSize:size type: CSType stresslevel:stress_indicator]) {
        NSLog(@"Creating new scene from CSDraw within the init");
    }
    return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    self.swiped = NO;
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    self.pathToDraw = CGPathCreateMutable();

    CGPathMoveToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);

    self.lineNode = [SKShapeNode node];
    self.lineNode.path = self.pathToDraw;
    self.lineNode.strokeColor = [SKColor blackColor];
    self.lineNode.lineWidth = 10;
    self.lineNode.zPosition = 50;

    [self addChild:self.lineNode];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    self.swiped = YES;
    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    CGPathAddLineToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);
    self.lineNode.path = self.pathToDraw;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    if(!self.swiped) { //user just tapped once, draw a single point
        SKSpriteNode *dot = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(10, 10)];
        dot.position = positionInScene;
        [self addChild: dot];

    } else { //calls touchesMoved
    }

    //[self.lineNode removeFromParent]; //comment out this line if you want line to remain on screen
    CGPathRelease(self.pathToDraw);
}
@end

这个类是根据我在中找到的代码编写的。

我在一个Sprite Kit iOS8游戏中遇到了类似的问题,并通过如下方式修复了它:尝试在touchesMoved函数中的CGPathAddLineToPoint调用之前添加一个CGPathMoveToPoint调用

根据CGPathAddLineToPoint的类引用,调用CGPathAddLineToPoint会自动“将当前点更新到指定位置(x,y)[新端点]”。然而,我的行在iOS8中无法正确渲染,直到我在每次调用CGPathAddLineToPoint之前手动调用CGPathMoveToPoint。不知道为什么会这样。可能是iOS8中的精灵套件的错误

请在下面找到修改后的代码,其中的更改标记为
/*new*/
注释。代码假定您有一个名为lastPointTouched的CGPoint属性

 @implementation CSDraw

-(id)initWithSize:(CGSize)size type:(NSString *)CSType stresslevel:(NSInteger)stress_indicator { //designated initializer
    if (self = [super initWithSize:size type: CSType stresslevel:stress_indicator]) {
        NSLog(@"Creating new scene from CSDraw within the init");
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    self.swiped = NO;
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    self.pathToDraw = CGPathCreateMutable();

    CGPathMoveToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);
    /* new */ self.lastPointTouched = positionInScene; 

    self.lineNode = [SKShapeNode node];
    self.lineNode.path = self.pathToDraw;
    self.lineNode.strokeColor = [SKColor blackColor];
    self.lineNode.lineWidth = 10;
    self.lineNode.zPosition = 50;

    [self addChild:self.lineNode];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    self.swiped = YES;
    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    /* new */ CGPathMoveToPoint(self.pathToDraw, NULL, self.lastPointTouched.x, self.lastPointTouched.y);
    CGPathAddLineToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);
    /* new */ self.lastPointTouched = positionInScene;
    self.lineNode.path = self.pathToDraw;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch* touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];

    if(!self.swiped) { //user just tapped once, draw a single point
        SKSpriteNode *dot = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(10, 10)];
        dot.position = positionInScene;
        [self addChild: dot];

    } else { //calls touchesMoved
    }

    //[self.lineNode removeFromParent]; //comment out this line if you want line to remain on screen
    CGPathRelease(self.pathToDraw);
}
@end