Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 意外的SpriteKit批处理绘图结果_Ios_Objective C_Sprite Kit_Drawing_Skspritenode - Fatal编程技术网

Ios 意外的SpriteKit批处理绘图结果

Ios 意外的SpriteKit批处理绘图结果,ios,objective-c,sprite-kit,drawing,skspritenode,Ios,Objective C,Sprite Kit,Drawing,Skspritenode,我目前正在使用SpriteKit和Objective-C开发一款iOS游戏。我最近一直在尝试优化我的绘制调用,但我遇到了一个问题,我要么误解了批绘制操作,要么收到了一些意想不到的结果。此外,我已经阅读了苹果公司关于批量绘图的文档,我只是担心我可能误解了一些指南 下面是详细说明:(假设所有地图集都已预加载,self是一个场景) 这正如您所期望的那样有效。第一次触摸将节点和绘图计数都增加+1。后续接触将添加到节点计数,但不会添加到绘制计数 /*Code Block 1:*/ -(void)touch

我目前正在使用SpriteKit和Objective-C开发一款iOS游戏。我最近一直在尝试优化我的绘制调用,但我遇到了一个问题,我要么误解了批绘制操作,要么收到了一些意想不到的结果。此外,我已经阅读了苹果公司关于批量绘图的文档,我只是担心我可能误解了一些指南

下面是详细说明:(假设所有地图集都已预加载,self是一个场景)

这正如您所期望的那样有效。第一次触摸将节点和绘图计数都增加+1。后续接触将添加到节点计数,但不会添加到绘制计数

/*Code Block 1:*/
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

SKSpriteNode *touch1 = [SKSpriteNode spriteNodeWithTexture:[[SKTextureAtlas atlasNamed:@"TouchAtlas1"] textureNamed:@"texture1"]];
[touch1 setPosition:location];
[self addChild:enemyTouch];
}
当我开始将两个来自不同地图集的精灵添加到父对象时,我开始收到太多的绘制调用。我所期望的:在第一次触摸时,我会得到+2个节点和+2个绘制调用,随后的触摸会产生+2个节点和+0个绘制调用。我得到的:在第一次触摸时,我得到了+2个节点和+2个绘制调用,随后的触摸产生了+2个节点和+2个绘制调用

/*Code Block 2:*/
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

SKSpriteNode *touch1 = [SKSpriteNode spriteNodeWithTexture:[[SKTextureAtlas atlasNamed:@"TouchAtlas1"] textureNamed:@"texture1"]];
[touch1 setPosition:location];
[self addChild:touch1];

SKSpriteNode *touch2 = [SKSpriteNode spriteNodeWithTexture:[[SKTextureAtlas atlasNamed:@"TouchAtlas2"] textureNamed:@"texture2"]];
[touch2 setPosition:location];
[self addChild:touch2];
}
我尝试了另外一个步骤,将子SKNode*外层添加到场景中,并将一个精灵添加到场景中,将一个精灵添加到外层中。这就产生了我上面想要的+2个节点和+0个绘图调用的理想结果

/*Code Block 3:*/
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

SKSpriteNode *touch1 = [SKSpriteNode spriteNodeWithTexture:[[SKTextureAtlas atlasNamed:@"TouchAtlas1"] textureNamed:@"texture1"]];
[touch1 setPosition:location];
[self addChild:touch1];

SKSpriteNode *touch2 = [SKSpriteNode spriteNodeWithTexture:[[SKTextureAtlas atlasNamed:@"TouchAtlas2"] textureNamed:@"texture2"]];
[touch2 setPosition:location];
[self.extraLayer addChild:touch2];
}

问题是:这实际上是处理批处理draw调用的方式吗?所有纹理来自公共地图集的精灵都需要是同一父级的子级,但该父级没有来自不同地图集的纹理的子级?或者,有没有一种方法可以正确地生成块2批处理的方法?

实际上,我无法生成您在“代码块2”示例中所说的内容。另外,我正在使用Swift。稍后我可以测试一个Obj-C版本的代码。实际上,我无法生成您在“代码块2”示例中所说的内容。另外,我正在使用Swift。我可以稍后测试Obj-C版本的代码。