我使用以下代码在我的精灵套件场景中绘制线条,但没有显示任何内容。但是节点数增加了。任何人都可以看到可能是什么问题。我一直在与这段代码作斗争
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
lineNode = [SKShapeNode node];
lineNode.path = pathToDraw;
lineNode.strokeColor = [SKColor redColor];
//lineNode.lineWidth = 2;
[self addChild:lineNode];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
CGPathAddLineToPoint(pathToDraw, NULL, positionInScene.x, positionInScene.y);
lineNode.path = pathToDraw;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// lineNode.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:pathToDraw];
// lineNode.physicsBody.dynamic = NO;
// lineNode.physicsBody.categoryBitMask = lines;
// lineNode.physicsBody.contactTestBitMask = 0;
// lineNode.physicsBody.collisionBitMask = blueParticles | redParticles| yellowParticles;
CGPathRelease(pathToDraw);
}
编辑-----删除后台节点后代码可以工作。如何设置后台节点以便我可以在上面进行操作?谢谢
SKSpriteNode *background;
if(screenHeight == 480){
background = [SKSpriteNode spriteNodeWithImageNamed:@"iPhone4BG.png"];
}
if(screenHeight == 568){
background = [SKSpriteNode spriteNodeWithImageNamed:@"iPhone5BG.png"];
}
if(screenHeight == 667){
background = [SKSpriteNode spriteNodeWithImageNamed:@"iPhone6BG.png"];
}
if(screenHeight == 736){
background = [SKSpriteNode spriteNodeWithImageNamed:@"iPhone6PlusBG.png"];
}
background.position = CGPointMake(screenWidth/2, screenHeight/2);
background.size = CGSizeMake(screenWidth, screenHeight);
// [self addChild:background];