Objective c NSMutableDictionary setObject:forKey随机设置null而不是object
我有一个精灵查看工具,可以帮助动画制作者预览精灵精灵。 我有一个这样的数据结构(伪) 我想要一种方法,为每一面创建3个精灵, 将它们并排放置并在其上运行纹理动画。 我决定使用SKAction:animateWithTextures来实现这一点 为了方便一次运行所有操作,我决定首先创建所需的所有SKActions,将它们存储在某个容器中,然后在所有精灵就绪后枚举容器并启动每个元素 所以我决定用NSMutableDictionary来解决这个问题 SKSpriteNode*作为键,SKAction*作为对象 -(SKSpriteNode*):(SKAction*)-字典中的每条记录 下面是填充外部创建的字典的方法(可以填充更多精灵) 我有时会得到这样的结果Objective c NSMutableDictionary setObject:forKey随机设置null而不是object,objective-c,debugging,sprite-kit,nsmutabledictionary,skaction,Objective C,Debugging,Sprite Kit,Nsmutabledictionary,Skaction,我有一个精灵查看工具,可以帮助动画制作者预览精灵精灵。 我有一个这样的数据结构(伪) 我想要一种方法,为每一面创建3个精灵, 将它们并排放置并在其上运行纹理动画。 我决定使用SKAction:animateWithTextures来实现这一点 为了方便一次运行所有操作,我决定首先创建所需的所有SKActions,将它们存储在某个容器中,然后在所有精灵就绪后枚举容器并启动每个元素 所以我决定用NSMutableDictionary来解决这个问题 SKSpriteNode*作为键,SKAction*
(lldb) po animatedSprites
{
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_down.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x608000027220>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_side_active.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = (null);
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_up.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60800002c040>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_side.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60800002fb80>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_up_active.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x600000030de0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_down_active.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = (null);
}
(lldb)po动画精灵
{
“名称:'(null)'纹理:['farmer_down.png'(340 x 340)]位置:{680,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_side_active.png'(340 x 340)]位置:{0,20}大小:{340,340}旋转:0.00”=(null);
“名称:'(null)'纹理:['farmer_up.png'(340 x 340)]位置:{340,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['farmer_side.png'(340 x 340)]位置:{0,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_up_active.png'(340 x 340)]位置:{340,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_down_active.png'(340 x 340)]位置:{680,20}大小:{340,340}旋转:0.00”=(null);
}
但有时我会这样
(lldb) po animatedSprites
{
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_side.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002f9e0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_side_active.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002c420>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_down.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x6000000302a0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_up.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x600000031120>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_up_active.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002b9a0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_down_active.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002b4a0>";
}
(lldb)po动画精灵
{
“名称:'(null)'纹理:['farmer_side.png'(340 x 340)]位置:{0,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_side_active.png'(340 x 340)]位置:{0,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['farmer_down.png'(340 x 340)]位置:{680,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['farmer_up.png'(340 x 340)]位置:{340,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_up_active.png'(340 x 340)]位置:{340,20}大小:{340,340}旋转:0.00”=”;
“名称:'(null)'纹理:['axe_down_active.png'(340 x 340)]位置:{680,20}大小:{340,340}旋转:0.00”=”;
}
结果总是随机的,唯一不变的特征是生物精灵总是好的,但物品精灵每次都随机为空,有时所有精灵都为空,有时没有
此外,png图集中我的一些精灵纹理实际上可以是空白的,RGBA信息为0,因为该物品在某些移动中可能会被生物精灵遮挡。在这种情况下,整个项目精灵与生物精灵大小相同,但其中每个像素都有零
我不知道该怀疑什么,如何处理这个调试问题。你能帮我吗
-(void)playPose{
if (_currentCreature){
NSMutableDictionary* animatedSprites = [NSMutableDictionary dictionary];
[self addAnimatedSpritesFromPlate:_currentCreature ToDict:animatedSprites];
if (_currentItem){
[self addAnimatedSpritesFromPlate:_currentItem ToDict:animatedSprites];
}
//I set breakpoint here and check animatedSprites
for (SKSpriteNode* sprite in [animatedSprites allKeys]){
SKAction* action = animatedSprites[sprite];
[self addChild:sprite];
[sprite runAction:action completion:^{
[sprite removeFromParent];
}];
}
}
}
(lldb) po animatedSprites
{
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_down.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x608000027220>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_side_active.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = (null);
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_up.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60800002c040>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_side.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60800002fb80>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_up_active.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x600000030de0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_down_active.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = (null);
}
(lldb) po animatedSprites
{
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_side.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002f9e0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_side_active.png' (340 x 340)] position:{0, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002c420>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_down.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x6000000302a0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'peasant_up.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x600000031120>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_up_active.png' (340 x 340)] position:{340, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002b9a0>";
"<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'axe_down_active.png' (340 x 340)] position:{680, 20} size:{340, 340} rotation:0.00" = "<SKAnimate: 0x60000002b4a0>";
}